我想要获得的效果与链接中的效果完全相同。问题是我做的方式并不完美。当我放大站点(按Ctrl +滚动)时,内容看起来不居中。最好的解决方案是使用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>
答案 0 :(得分:2)
您可以将circle元素设置为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>
答案 1 :(得分:0)
我认为问题不在于代码。因为当我扩大站点时我没有任何问题。您也可以使用em或rm代替px。