3. CSS Selector
Cách sử dụng CSS căn bản
Cài đặt CSS
Hướng dẫn cài đặt CSS cho HTML:
- Sử dụng extenal CSS:
<link rel="stylesheet" href="style.css"> - Sử dụng internal CSS:
<style>...</style> - Sử dụng inline CSS:
<h1 style="color:blue;">This is a Blue Heading</h1>
Cú pháp CSS
- Tag selector / locator:
tagname { property: value; }
h1 {
color: blue;
font-size: 12px;
}
- Class selector / locator:
.classname { property: value; }
.center {
text-align: center;
color: red;
}
- ID selector / locator:
#idname { property: value; }
#intro {
font-family: Arial;
font-size: 20px;
}
Các nhóm thuộc tính CSS căn bản
Nhóm font chữ
Gồm các thuộc tính:
- font-family: tên font chữ, tham khảo: https://www.w3schools.com/cssref/css_websafe_fonts.asp
- Ví dụ:
font-family: Arial, Helvetica, sans-serif;
- Ví dụ:
- font-size: kích thước font chữ, tham khảo: https://www.w3schools.com/cssref/css_units.asp
- Ví dụ:
font-size: 20px;
- Ví dụ:
- font-weight: độ đậm nhạt của font chữ, tham khảo: https://www.w3schools.com/cssref/pr_font_weight.asp
- Ví dụ:
font-weight: bold;
- Ví dụ:
- font-style: kiểu chữ, tham khảo: https://www.w3schools.com/cssref/pr_font_font-style.asp
- Ví dụ:
font-style: italic;
- Ví dụ:
- font-variant: kiểu chữ, tham khảo: https://www.w3schools.com/cssref/pr_font_font-variant.asp
- Ví dụ:
font-variant: small-caps;
- Ví dụ:
- font: gộp các thuộc tính trên
- Ví dụ:
font: italic small-caps bold 20px Arial, Helvetica, sans-serif;
- Ví dụ:
Nhóm màu sắc
Gồm các thuộc tính:
- color: màu chữ, tham khảo: https://www.w3schools.com/cssref/css_colors.asp
- Ví dụ:
color: red;
- Ví dụ:
- background-color: màu nền, tham khảo: https://www.w3schools.com/cssref/css_colors.asp
- Ví dụ:
background-color: yellow;
- Ví dụ: