CSS cung cấp nhiều thuộc tính để định dạng văn bản, giúp nội dung trở nên dễ đọc và hấp dẫn hơn. Điều này rất quan trọng trong thiết kế web để cải thiện trải nghiệm người dùng.
font-familyVí dụ:
p {
font-family: Arial, Helvetica, sans-serif;
}
font-sizepx, em, %, rem, vw, vh...em và rem giúp kích thước chữ linh hoạt theo cài đặt của trình duyệt.Ví dụ:
h1 {
font-size: 24px;
}
font-weightnormal, bold, lighter, bolder, hoặc số từ 100 đến 900 (trong đó 400 là normal, 700 là bold).Ví dụ:
strong {
font-weight: bold;
}
line-heightnormal, số, %, px, em...1.5 hoặc 2 để dễ đọc hơn.Ví dụ:
p {
line-height: 1.5;
}
text-alignleft, right, center, justify.justify: Căn đều hai bên.Ví dụ:
div {
text-align: justify;
}
CSS cung cấp các thuộc tính để kiểm soát cách hiển thị danh sách:
list-style-typedisc: Hình tròn đậm mặc định.circle: Hình tròn rỗng.square: Hình vuông.none: Không có dấu đầu dòng.decimal: Số thứ tự (1, 2, 3, ...).lower-roman: Số La Mã viết thường (i, ii, iii, ...).upper-roman: Số La Mã viết hoa (I, II, III, ...).lower-alpha: Chữ cái viết thường (a, b, c, ...).upper-alpha: Chữ cái viết hoa (A, B, C, ...).Ví dụ:
ul {
list-style-type: square;
}
list-style-positioninside hoặc outside.inside: Dấu đầu dòng nằm trong phần nội dung.outside: Dấu đầu dòng nằm ngoài lề văn bản (mặc định).Ví dụ:
ul {
list-style-position: inside;
}
list-style-imageVí dụ:
ul {
list-style-image: url('icon.png');
}
Ví dụ:
<ul>
<li>Mục 1
<ul>
<li>Mục 1.1</li>
<li>Mục 1.2</li>
</ul>
</li>
<li>Mục 2</li>
</ul>
Bảng là một phần quan trọng trong thiết kế web. CSS giúp điều chỉnh bảng để dễ nhìn hơn.
borderborder-collapse: collapse; để gộp viền thành một.Ví dụ:
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
paddingVí dụ:
td {
padding: 10px;
}
text-align và vertical-aligntext-align: Căn chỉnh nội dung theo chiều ngang (left, center, right).vertical-align: Căn chỉnh theo chiều dọc (top, middle, bottom).Ví dụ:
th, td {
text-align: center;
vertical-align: middle;
}
background-colorVí dụ:
table {
background-color: #f2f2f2;
}
th {
background-color: #ddd;
}
width và heightwidth: auto; giúp bảng tự động điều chỉnh theo nội dung.%, vw/vh để thiết lập kích thước linh hoạt.Ví dụ:
table {
width: 100%;
}
th, td {
height: 50px;
}
Việc sử dụng các thuộc tính CSS để định dạng văn bản, danh sách và bảng giúp cải thiện giao diện trang web và nâng cao trải nghiệm người dùng. Hãy thực hành để làm chủ những kỹ thuật này!
CODE BÀI GIẢNG
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Code bài 5: chia khung</title>
<style>
body {
font-family: Arial;
}
.call {
position: fixed;
bottom: 50px;
right: 50px;
width: 50px;
height: 50px;
}
/*CSS UL MENU*/
.menu {
width: 100%;
height: 70px;
position: sticky;
top: 0px;
padding-left: 200px;
padding-right: 200px;
display: flex;
box-sizing: border-box;
align-items: center;
}
.menu img {
height: 60px;
width: auto;
left: 200px;
}
.menu ul {
flex: 1;
text-align: right;
}
.menu ul li {
display: inline-block;
padding: 10px 15px;
}
.menu ul li a {
font-weight: 700;
color: #515151;
text-decoration: none;
font-size: 13px
}
.menu button {
padding: 12px 20px;
background: #ff6a00;
color: white;
border: none;
border-radius: 30px;
font-size: 14px;
}
/* CSS BANNER*/
.banner {
width: 100%;
height: 600px;
padding-top: 200px;
padding-left: 200px;
box-sizing: border-box;
position: relative;
}
.banner .hello {
top: 250px;
left: 200px;
}
.banner h1 {
top: 0;
left: 0;
font-size: 80px;
line-height: 0;
}
.banner h2 {
top: 150px;
line-height: 0;
}
.banner button {
padding: 12px 20px;
background: #ff6a00;
color: white;
border: none;
border-radius: 30px;
font-size: 14px;
font-weight: bold;
}
.banner button.black {
background-color: black;
}
.banner .social-box {
margin-top: 20px;
display: flex;
}
.banner .social-box .social {
display: block;
border: 2px solid #ff6a00;
width: 40px;
height: 40px;
margin-right: 20px;
text-align: center;
padding: 10px 10px;
box-sizing: border-box;
color: #ff6a00;
font-weight: bold;
border-radius: 20px
}
.banner .social-box .social:hover {
background: #ff6a00;
color: white;
cursor: pointer
}
.banner img {
position: absolute;
right: 200px;
bottom: 0;
height: 600px
}
</style>
</head>
<body>
<!-- Menu -->
<section class="menu">
<img src="logo.svg" />
<ul>
<li>
<a href="#">Home</a>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Service</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Testmonial</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div>
<button>Components</button>
</div>
</section>
<!-- banner -->
<section class="banner">
<div class="hello">
hello,I'm
</div>
<h1>
James Smith
</h1>
<h2>
UI/UX Designer
</h2>
<div>
<button>HIRE ME</button>
<button class="black">DOWNLOAD CV</button>
</div>
<div class="social-box">
<a class="social">F</a>
<a class="social">G</a>
<a class="social">T</a>
<a class="social">W</a>
</div>
<img src="man.svg" />
</section>
<img class="call" src="https://cdn-icons-png.flaticon.com/512/9073/9073336.png" />
</body>
</html>