gpt4 book ai didi

html - 调整伪元素宽度

转载 作者:太空宇宙 更新时间:2023-11-04 07:35:29 24 4
gpt4 key购买 nike

如何在不设置 .item-class 的填充/边距的情况下调整伪元素的宽度?假设我想在边框的每一侧留出 20 像素。

HTML

 <div class="container">
<div class="item">
<p>Box 1</p>
</div>
<div class="item">
<p>Box 2</p>
</div>
</div>

CSS

.container {
width: 200px;
height: 200px;
display: flex;
flex-direction: column;
}

.item {
position: relative;
display: flex;
flex: 1;
}

.item:after {
width: 100%; // ?
height: inherit;
position: absolute;
border-bottom: 1px solid #000;
content: " ";
}

最佳答案

像这样简单地使用left/right:

.container {
width: 200px;
height: 200px;
display: flex;
flex-direction: column;
}

.item {
position: relative;
display: flex;
flex: 1;
}

.item:after {
left:20px;
right:20px;
height: inherit;
position: absolute;
border-bottom: 1px solid #000;
content: " ";
}
<div class="container">
<div class="item">
<p>Box 1</p>
</div>
<div class="item">
<p>Box 2</p>
</div>
</div>

关于html - 调整伪元素宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48998095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com