gpt4 book ai didi

css - 阻止 child 覆盖 parent 的轮廓?

转载 作者:行者123 更新时间:2023-12-05 02:20:31 25 4
gpt4 key购买 nike

由于一些元素在幻灯片中,我使用带负偏移的轮廓而不是边框​​。

但是子元素覆盖了轮廓,但我想要它们的边框。我用它来构建内容。

http://jsfiddle.net/z22kw2zq/1/

.parent {
position:relative; outline: green 3px solid;
outline-offset:0px;
background-color:pink;
pading:5px;
overflow:hidden;
}
.child {position:relative; top:26px; background-color:yellow;
display:inline;
}

最佳答案

您可以使用 :after 伪元素作为轮廓并添加 position: absolute

.parent {
position: relative;
background-color: pink;
overflow: hidden;
}
.parent:after {
width: 100%;
height: 100%;
content: '';
outline: green 3px solid;
outline-offset: -3px;
position: absolute;
top: 0;
left: 0;
}
.child {
position: relative;
top: 23px;
background-color: yellow;
display: inline;
}
p {
margin: 0;
}
<div class="parent">
<div class="child">lorem ipsum doler sit amet</div>
<p>text here</p>
</div>

关于css - 阻止 child 覆盖 parent 的轮廓?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38996342/

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