gpt4 book ai didi

html - CSS - 垂直时间轴,连接到点

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

到目前为止,这是我的时间线代码,我想以黄线结束最后一个 timeline-post 元素,然后到最后一个蓝点。

我试图添加这个类 .timeline:last-child::after 但这显然不起作用!

.iconspace {
position: relative;
width: 40px;
height: 40px;
text-align: center;
margin: 0 auto;
border-radius: 50%;
background-color: #25b5f1;
z-index: 7;
}

.iconspace i {
font-size: 18px;
color: #FFFFFF;
line-height: 40px;
}

.timeline {
position: relative;
}

.timeline:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 49.8%;
width: 3px;
height: 100%;
background-color: RED;
z-index: -5;
}

.timeline-post {
height: 100px;
width: 200px;
background-color: green;
margin: 0 auto;
margin-top: 20px;
}

.timeline:last-child::after {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 49.8%;
width: 3px;
height: 100%;
background-color: YELLOW;
z-index: -5;
}

.timeline:after {
position: absolute;
content: "";
display: inline-block;
width: 15px;
height: 15px;
line-height: 1;
background-color: #25b5f1;
margin-top: 50px;
left: 49.8%;
border-radius: 50%;
text-align: center;
}
<h3 class="entry-title" style="text-align: center;">EDUCATION</h3><span class="border"></span>
<div class="timeline">
<div class="iconspace"><i class="fa fa-graduation-cap"></i></div>

<div class="timeline-post">
Test 1
</div>

<div class="timeline-post">
Test 2
</div>

<div class="timeline-post">
Test 3
</div>
</div>

最佳答案

您需要将 last-child 应用到 timeline-post 而不是 timeline。您还需要在底部设置负值而不是使用 height:100% 否则您的线将采用与时间线帖子相同的高度并且永远不会到达蓝点。

当使用 position:absolute 及其伪元素或任何子元素时,也永远不要忘记将 position:relative 添加到元素。

.iconspace {
position: relative;
width: 40px;
height: 40px;
text-align: center;
margin: 0 auto;
border-radius: 50%;
background-color: #25b5f1;
z-index: 7;
}

.iconspace i {
font-size: 18px;
color: #FFFFFF;
line-height: 40px;
}

.timeline {
position: relative;
}

.timeline:before {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 49.8%;
width: 3px;
height: 100%;
background-color: RED;
z-index: -5;
}

.timeline-post {
height: 100px;
width: 200px;
background-color: green;
margin: 0 auto;
margin-top: 20px;
}

.timeline:after {
position: absolute;
content: "";
display: inline-block;
width: 15px;
height: 15px;
line-height: 1;
background-color: #25b5f1;
margin-top: 50px;
left: 49.8%;
border-radius: 50%;
text-align: center;
}

.timeline .timeline-post {
position: relative;
}

.timeline .timeline-post:last-child::after {
content: "";
display: block;
position: absolute;
top: 0;
bottom: -50px;
left: 49.8%;
width: 3px;
background-color: YELLOW;
z-index: -5;
}
<h3 class="entry-title" style="text-align: center;">EDUCATION</h3><span class="border"></span>
<div class="timeline">
<div class="iconspace"><i class="fa fa-graduation-cap"></i></div>

<div class="timeline-post">
Test 1
</div>

<div class="timeline-post">
Test 2
</div>

<div class="timeline-post">
Test 3
</div>
</div>

关于html - CSS - 垂直时间轴,连接到点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47367122/

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