CSS中左右边框对齐怎么弄?
在CSS中,如果我们想要给一个元素同时添加左右边框,通常会这样写代码:
css
.example {
border-left: 2px solid red;
border-right: 2px solid red;
} css
.example {
border-left: 2px solid red;
border-right: 2px solid red;
padding: 0 5px;
} css
.example {
box-sizing: border-box;
border-left: 2px solid red;
border-right: 2px solid red;
} css
.example {
position: relative;
}
.example::before,
.example::after {
content: "";
position: absolute;
top: 0;
bottom: 0;
width: 2px;
background-color: red;
}
.example::before {
left: 0;
}
.example::after {
right: 0;
}