'Vertical divider CSS
I am creating a vertical divider, that works fine. But the CSS is cumbersome.
The CSS is:
.headerDivider1 {
border-left:1px solid #38546d;height:80px;position:absolute;right:250px;top:10px;
}
.headerDivider2 {
border-left:1px solid #16222c;height:80px;position:absolute;right:249px;top:10px;
}
The HTML is:
<div class="headerDivider1"></div><div class="headerDivider2"></div>
The result is:
How could I tidy the HTML and CSS up?
Solution 1:[1]
.headerDivider {
border-left:1px solid #38546d;
border-right:1px solid #16222c;
height:80px;
position:absolute;
right:249px;
top:10px;
}
<div class="headerDivider"></div>
Solution 2:[2]
<div class="headerdivider"></div>
and
.headerdivider {
border-left: 1px solid #38546d;
background: #16222c;
width: 1px;
height: 80px;
position: absolute;
right: 250px;
top: 10px;
}
Solution 3:[3]
for vertical divider only
.divider {
border-left: 1px solid #000;
height: 100%;
}
Solution 4:[4]
I prefer using the after
property for vertical divider using CSS because it's neither content nor a border.
.block {
position: relative; /* ADDED */
}
.block:after {
content: '';
position: absolute;
border-left: 1px solid black;
right: -10px;
height: 80%;
}
.block:last-child:after {
display: none; /* Hide the divider for the last block */
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | amosrivera |
Solution 2 | orlp |
Solution 3 | Niket Tongare |
Solution 4 | Balram Singh |