wiki

View on GitHub

HTML&CSS coding convention

HTML Convention

Tất cả các thẻ (tags) phải là chữ thường

<table></table>
<form></form>

Sử dụng tên ý nghĩa khi đặt cho ID và các phần tử HTML

txtName, txtAge

thay vì

text1, text2

Indent HTML code consistently (Thụt lề cho mã HTML)

<body>
    <form name="frmActivity" method="post" action="<?php echo $formAction;?>">
        <input type="hidden" name="sqlState" value="">
        <input type="hidden" name="delState" value="">
        <input type="hidden" name="activityId" value="">
        <label for="cmbProjectId"></label>
        <select name="cmbProjectId">
            <option value="value1"></option>
        </select>
    </form>
</body>

Không sử dụng inline style attributes

Hạn chế sử dụng nó càng ít càng tốt, điều này có những lợi thế sau:

...

// USE

...

```

Sử dụng 1 file CSS riêng không đặt trong trang HTML

Tuân thủ W3C validate

CSS Convention

Không tốt

#some-body {
  // ...
}

Tốt

.some-body {
  // ...
}

Không tốt

.logo, .navigation, .title{
  // ...
}

Tốt

.logo, 
.navigation, 
.title {
  // ...
}

Không tốt

.selector{
  // ...
}

.selector       {
  // ...
}

Tốt

.selector {
  // ...
}

Không tốt

.selector{
  width:100%;
}

Tốt

.selector {
  width: 100%;
}

Không tốt

.selector{
  width:100%;
}
.bar{
  width:100%;
}

Tốt

.selector{
  width:100%;
}

.bar{
  width:100%;
}

Không tốt

.foo {
  border: none;
}

Tốt

.foo {
  border: 0;
}

SCSS

Tốt

.lever-1{
  .lever-2{
    .lever-3{
      // Done
    }
  }
}

Tốt

.btn-green {
  background: green;
  font-weight: bold;
  @include transition(background 0.5s ease);
  // ...
} * Giữa các selector phải có khoảng trống

Tốt

.btn {
  background: green;
  font-weight: bold;
  @include transition(background 0.5s ease);
  
  .icon {
    margin-right: 10px;
  }
}

Đặt tên cho class

Phân chia section rõ ràng

Đặt tên class theo chức năng và hướng tới “Đối tượng”