gpt4 book ai didi

带有 :before and :after 边框的 CSS 点

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

我想要的效果看起来和链接中的一模一样。问题是我做的方式并不完美。当我放大网站 (ctrl + scroll) 时,内容看起来不居中。最好的解决方案是使用 CSS :before 和 :after,我想保持这种方式。

https://jsfiddle.net/4a9c3p5q/3/

div {
width: 120px;
height: 50px;
position: relative;
}

div::before {
content: "";
height: 100%;
width: 2px;
position: absolute;
right: 10px;
background: red;
}

div::after {
content: "\00B7";
color: red;
background: white;
position: absolute;
top: 0;
right: 2px;
font-size: 70px;
padding: 2px;
border: 2px solid red;
border-radius: 50%;
width: 10px;
height: 10px;
display: flex;
align-items: center;
justify-content: center;
}
<div>Sample text.</div>
<div>Sample text.</div>
<div>Sample text.</div>
<div>Sample text.</div>

最佳答案

您可以将圆形元素设为 inline-block,这样您就可以轻松地将其与文本垂直对齐:

div.timeline >div {
width: 120px;
padding-bottom:35px;
position: relative;
/*to replace the line*/
background:
linear-gradient(red,red) right 9px top 19px/2px 100% no-repeat;
margin-bottom:-2px;
}


div.timeline > div::after {
content: "";
display:inline-block;
margin-left:20px;
vertical-align:middle;
color: red;
/*to replace the circle*/
background:red content-box;
padding: 4px;
border: 2px solid red;
border-radius: 50%;
width: 8px;
height: 8px;
}
<div class="timeline">
<div>Sample text.</div>
<div>Sample text.</div>
<div>Sample text.</div>
<div>Sample text.</div>
</div>

关于带有 :before and :after 边框的 CSS 点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54727943/

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