Trong bài viết này, chúng ta sẽ xem cách thêm Đường kẻ ngang trong HTML. Đối với điều này, có 2 cách tiếp cận
- By using the tag
- Bằng cách sử dụng Thuộc tính CSS
Chúng tôi sẽ thảo luận tuần tự cả hai cách tiếp cận để thêm đường ngang
Adding the Horizontal Line using tag: The Horizontal Rule tag [] is used for the purpose of inserting horizontal lines in the HTML document in order to separate sections of the document. It is an empty or unpaired tag that means there is no need for the closing tag.
cú pháp
Example 1: This example describes the tag to add the horizontal line.
HTML
.lineHorizontal__container {2
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {3
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {4
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
_______43____48____45
0______43____421
.lineHorizontal__container {22
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {21
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {25
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {8
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {3
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {30
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
0______43____434
.lineHorizontal__container {22
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {34
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
0______43____440
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
0______43____444
.lineHorizontal__container {45
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {44
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
_______425____430____45
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {25
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {4
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
đầu ra
Example 2: This example describes the tag with various attribute & their values to style the horizontal line.
HTML
.lineHorizontal__container {2
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {3
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {4
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
_______43____48____45
0______43____421
.lineHorizontal__container {66
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {21
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {25
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {8
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {3
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {30
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
0______43____434
.lineHorizontal__container {39
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {34
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
0______43____440
.lineHorizontal__container {85
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {86
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {87
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {88
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {89
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {86
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {51
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {88
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {53____486
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {55
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
0______43____440
.lineHorizontal__container {85
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {86
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {87
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {88
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {89
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {86
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {51
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {88
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {53____486
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {200
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
_______488____4202____486____4204
.lineHorizontal__container {205
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
0______43____440
.lineHorizontal__container {85
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {86
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {211
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {88
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {202____486
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {215
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
_______488____489____486
.lineHorizontal__container {219
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {88
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {53____486
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {223
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {224
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
_______425____430____45
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {25
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {4
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {5
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
đầu ra
Thêm đường Ngang bằng Thuộc tính CSS. Trong trường hợp này, chúng ta sẽ sử dụng Thuộc tính kiểu viền để tạo đường kẻ ngang. Chúng ta có thể sử dụng thuộc tính border-top chỉ định kiểu của đường viền trên cùng hoặc thuộc tính border-bottom, có thể đặt kiểu cho đường viền dưới cùng của một phần tử. Cả hai thuộc tính có thể được sử dụng để thêm đường ngang
ví dụ 3. Ví dụ này mô tả cách vẽ đường ngang bằng Thuộc tính kiểu viền
2. Chris Coyier thực hiện tổng quan toàn diện về cách vẽ các đường ngang bằng CSS. Rất khuyến khích
Trong hướng dẫn tiêu chuẩn về viết mã HTML/CSS, bạn sẽ không học cách vẽ một đường ngang. Ít nhất thì tôi đã không làm như vậy khi tôi học tại CodeCademy [mặc dù đó là một khóa học tuyệt vời]
Vì vậy, lần đầu tiên tôi phải vẽ một cái, tôi đã phải vật lộn
Điều quan trọng là nhận thức một đường thẳng như một phần của đường viền hộp. Sử dụng thuộc tính CSS
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Để biết cách tiếp cận khác, hãy xem bài viết khác trên Phương tiện của tôi về việc sử dụng phần tử
.lineHorizontal__container {7 với
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}.lineHorizontal__container {8 và
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}.lineHorizontal__container {9
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Hình trên được tạo bằng cách viết mã HTML và CSS như sau. Đầu tiên, mã HTML
Tôi tuân theo quy ước BEM về đặt tên các lớp tại đây
Lớp
0 định nghĩa một đường ngang. Các lớp
1 và
2 thay đổi độ dài của một dòng. Để định vị từng dòng, tôi đính kèm mỗi lớp
0 với lớp
4. Các lớp còn lại được sử dụng để định vị từng dòng theo một cách khácVà mã CSS
.lineHorizontal__container {
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Lưu ý rằng tôi áp dụng quy ước sắp xếp thứ tự bảng chữ cái cho mã hóa CSS. Nó giúp tiết kiệm thời gian viết mã [bạn không cần phải suy nghĩ xem nên sắp xếp các thuộc tính CSS theo thứ tự nào] và giúp dễ dàng kiểm tra xem một thuộc tính nhất định có được xác định hay không và cách thức xác định [hãy tưởng tượng một từ điển sao chép trên giấy không được sắp xếp theo thứ tự bảng chữ cái…đó là một
Dưới đây tôi phá vỡ mã này từng chút một
Vẽ các đường ngangĐầu tiên, vẽ một đường ngang đơn giản trên toàn bộ màn hình bằng mã HTML
và một mã CSS
.lineHorizontal__container {3
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Lớp
4 với
6 và
7 [hoặc bất kỳ giá trị chiều cao nào] đảm bảo rằng dòng xuất hiện ở giữa màn hình, thay vì cạnh trên gần nhất. Vì vậy, chúng tôi có một cái gì đó như thế nàyĐộ dày của đường được đặt thành
8. Tất nhiên chúng ta có thể làm dày nó lên. Nhưng trong hầu hết các trường hợp, tốt hơn là nên có các đường kẻ càng mỏng càng tốt. Ngay cả với chiều rộng 1px, chúng ta có thể nhìn thấy rõ ràng. Vai trò của các dòng trên một trang web là tăng cường tổ chức thông tin. Bản thân các dòng gần như chắc chắn sẽ không có giá trị thông tin. Vì vậy, chúng tôi không muốn họ nổi bậtKiểu đường kẻ được đặt thành
9. Tất nhiên chúng ta có thể thay đổi điều này thành .lineHorizontal__container {30 hoặc
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {31. Nhưng kiểu đường như vậy truyền đạt ý nghĩa riêng của nó [chẳng hạn như vô thường] và trừ khi ý nghĩa đó là cần thiết trong thiết kế trang web, chúng ta nên chọn một đường liền nét đơn giản
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Đối với màu đường kẻ, tôi tạm thời sử dụng
.lineHorizontal__container {32. Một trong những mẹo thiết kế đồ họa tiêu chuẩn là tốt nhất nên tránh sử dụng màu đen thuần trên nền trắng thuần vì nó quá chói đối với mắt của chúng ta. Tôi tin rằng mắt người không quen với màu đen thuần khiết vì không có vật chất nào trong thế giới vật chất là hoàn toàn đen. Màu đen tuyền là sự sáng tạo nhân tạo của màn hình máy tính
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Sau đó chúng tôi thêm hai dòng nữa
.lineHorizontal__container {2
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Nhờ có lớp
4 với các giá trị thuộc tính CSS của nó là
6 và
7, ba dòng này sẽ không được vẽ ở cùng một vị trí, như được hiển thị bên dướiMỗi dòng cách nhau 80pxThay đổi độ dài của dòng
Bây giờ chúng tôi muốn làm cho mỗi dòng ngắn hơn, với dòng ở giữa là ngắn nhất. Vì vậy, chúng tôi thêm các lớp sửa đổi
.lineHorizontal__container {6
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
và đặt độ dài dòng trong các lớp mới này
.lineHorizontal__container {7
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
để chúng ta có ba dòng xuất hiện như thế này
Định vị từng dòng
Cuối cùng, chúng tôi muốn căn phải hai dòng cuối cùng. Tốt nhất là sử dụng flexbox để định vị từng dòng
.lineHorizontal__container {8
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
với mã CSS
.lineHorizontal__container {9
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Theo mặc định, giá trị của thuộc tính
.lineHorizontal__container {36 là
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {37. Nhưng để dễ đọc mã, nên làm cho mã rõ ràng
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Bây giờ chúng ta có cái này
Bằng cách nào đó nó bắt đầu trông arty một chút. Tôi nghĩ đó là vì bố cục các đường này nhắc chúng ta về chuyển động ngang của những đám mây phản chiếu trên mặt nước. Thiên nhiên là nguồn cảm hứng quan trọng nhất cho nghệ thuật
Nếu bạn cần đặt một dòng cách xa mép bên của màn hình, hãy sử dụng
.lineHorizontal__container {38 hoặc
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {39 cho div vùng chứa
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {4
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
và thêm khai báo CSS sau
.lineHorizontal__container {0
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Sau đó, dòng cuối cùng được tách ra khỏi cạnh phải bằng 10% chiều rộng của toàn bộ màn hình
Điều tương tự cũng có thể đạt được bằng cách áp dụng thuộc tính
.lineHorizontal__container {20 cho chính dòng đó
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
.lineHorizontal__container {1
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
và thêm khai báo CSS sau
.lineHorizontal__container {2
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Nhưng để dễ đọc mã, tất cả các thuộc tính định vị phải được đặt cho div vùng chứa
Thay đổi màu của các dòngĐể thêm một chút thay đổi, tôi đã thay đổi màu của các đường kẻ và nền của chúng
.lineHorizontal__container {3
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Bây giờ chúng tôi có hình ảnh ở đầu bài viết này
Tôi đã trực giác chọn màu
.lineHorizontal__container {21 cho nền có lẽ vì tôi đã quen nhìn thấy các sản phẩm sơn mài màu đỏ từ Nhật Bản lịch sử
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}
Để tạo sự tương phản đẹp mắt nhưng tinh tế với nó, tôi kết xuất các dòng trong
.lineHorizontal__container {22. Nó có màu xám xanh. Màu đỏ và màu xanh khi đặt cạnh nhau sẽ làm cho nhau trông rực rỡ hơn [đọc Tầm nhìn và Nghệ thuật. sinh học của việc nhìn, nếu bạn quan tâm đến lý do khoa học cho điều này] Vì vậy, một chút màu xanh trong màu xám làm cho những đường này trông đẹp hơn trên nền màu đỏ
align-items: center;
background-color: firebrick;
display: flex;
height: 80px;
}.lineHorizontal__container--leftAligned {
justify-content: flex-start;
}.lineHorizontal__container--rightAligned {
justify-content: flex-end;
}.lineHorizontal__container--detachedFromRight {
padding-right: 10%;
}.lineHorizontal {
border-top: 1px solid azure;
}.lineHorizontal--long {
width: 70%;
}.lineHorizontal--short {
width: 40%;
}