gpt4 book ai didi

css - 使用 :after 在 div 的右上角定位一个框

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

我试图在 div 上放置一个标签,本质上是使用 :after 伪类。很像 old bootstrap example blocks

JS Fiddle illustrating what I'm trying

CSS:

.blah {
border: 1px solid black;
border-radius: 5px;
padding: 5px;
margin: 5px;
}
.blah:after {
content: 'anyway';
position: absolute;
top: 0;
right: 0;
border: 1 px solid gray;
padding: 3px;
border-radius: 0 4px 0 4px;
}

本质上,我想将 after box 粘贴在目标 div 类的右上角,但它会弹出到 body 的右上角。

最佳答案

绝对定位的元素相对于其最近的具有位置的父元素定位。

position: relative 添加到 .blah 可以解决这个问题。

关于css - 使用 :after 在 div 的右上角定位一个框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25416981/

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