gpt4 book ai didi

html - 添加元素时时间轴 slider 被压缩

转载 作者:行者123 更新时间:2023-11-27 23:28:52 25 4
gpt4 key购买 nike

我正在尝试构建一个带有 slider 的时间轴,您可以在其中隐藏更多元素,单击按钮时,它会滑动并显示隐藏的元素。问题是当我添加更多元素时,它会收缩其他元素以适应 div,但我需要它来隐藏通过 div 边缘的元素,并且我可以通过水平滚动条或单击按钮来显示它们。

谁能帮帮我??

这是我到目前为止的代码,如果您想查看问题,只需将更多元素添加到列表中即可。

https://codepen.io/Arthur_Oliveira/pen/GRKNGBb

.timeline-background {
position: relative;
width: 100%;
height: 300px;
background-color: #F5F5F5;
padding: 0;
padding-top: 50px;
}

.list-items {
position: absolute;
width: auto;
height: auto;
margin: 0;
padding: 0;
margin-top: 20px;
max-width: 400px;
overflow: hidden;
object-fit: cover;
}

.list-item {
position: absolute;
width: 500px;
top: 0;
height: auto;
margin: 0;
padding: 0;
}

.list-items li {
position: relative;
display: flex;
}

.list-item li:first-child {
position: absolute;
left: 78px;
top: 63px;
cursor: pointer;
list-style: none;
width: 30px;
height: 30px;
background-color: #fff;
border: 3px solid #AD80FF;
color: #D9D9D9;
border-radius: 50%;
float: left;
}

.list-item li:last-child {
position: absolute;
right: -13px;
top: 63px;
cursor: pointer;
list-style: none;
width: 30px;
height: 30px;
margin-left: 50px;
background-color: #fff;
border: 3px solid #AD80FF;
color: #D9D9D9;
border-radius: 50%;
float: left;
}

.list-item li:last-child:hover {
color: #FF04FF;
}

.list-item li:first-child:hover {
color: #FF04FF;
}

.list-item .active {
}

.list-items li {
cursor: pointer;
margin-left: 50px;
list-style: none;
width: 15px;
height: 15px;
background-color: #fff;
border: 3px solid #D9D9D9;
margin-top: 0;
border-radius: 50%;
float: left;
}

.list-items li.active {
cursor: pointer;
margin-left: 50px;
list-style: none;
border: 3px solid #FF04FF;
background-color: #FF04FF;
border-radius: 50%;
float: left;
}

.list-item li:first-child:after {
cursor: initial;
position: absolute;
content: '';
width: 50px;
margin-top: -6px;
margin-left: 40px;
height: 50%;
border-bottom: 2px solid #D9D9D9;
z-index: 0;
}

.list-items li:after {
cursor: initial;
position: absolute;
content: '';
width: 50px;
margin-top: 0px;
margin-left: 15px;
height: 50%;
border-bottom: 2px solid #D9D9D9;
z-index: 0;
}

.list-item ul .actived:after {
border-bottom: 2px solid #FF04FF;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex justify-content-center timeline-background">
<div class="d-flex justify-content-center">
<div class="list-items">
<ul class="d-flex d-xl-flex justify-content-center align-items-center justify-content-xl-center">
<li class="active"><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>

</ul>
</div>
<div class="list-item">
<ul>
<li class="d-flex d-sm-flex d-md-flex d-lg-flex d-xl-flex justify-content-center align-items-center justify-content-sm-center align-items-sm-center justify-content-md-center align-items-md-center actived" href="#list1"><i class="icon ion-ios-arrow-back"></i></li>
<li class="d-flex justify-content-center align-items-center"><a class="item" href="#"></a><i class="icon ion-ios-arrow-forward"></i></li>
</ul>
</div>
</div>
</div>

更新::我将类列表项更改为:

.timeline-background {
position: relative;
width: 100%;
height: 300px;
background-color: #F5F5F5;
padding: 0;
padding-top: 50px;
}

.list-items {
position: relative;
width: auto;
height: auto;
margin: 0;
padding: 0;
margin-top: 20px;
margin-left: 86px;
max-width: 440px;
}



.list-item {
position: absolute;
width: 500px;
top: 0;
height: auto;
margin: 0;
padding: 0;
}

.list-items li {
position: relative;
display: flex;
}

.list-item li:first-child {
position: absolute;
left: 78px;
top: 63px;
cursor: pointer;
list-style: none;
width: 30px;
height: 30px;
background-color: #fff;
border: 3px solid #AD80FF;
color: #D9D9D9;
border-radius: 50%;
float: left;
}

.list-item li:last-child {
position: absolute;
right: -13px;
top: 63px;
cursor: pointer;
list-style: none;
width: 30px;
height: 30px;
margin-left: 50px;
background-color: #fff;
border: 3px solid #AD80FF;
color: #D9D9D9;
border-radius: 50%;
float: left;
}

.list-item li:last-child:hover {
color: #FF04FF;
}

.list-item li:first-child:hover {
color: #FF04FF;
}

.list-item .active {
}

.list-items li {
cursor: pointer;
margin-left: 50px;
list-style: none;
width: 15px;
height: 15px;
background-color: #fff;
border: 3px solid #D9D9D9;
margin-top: 0;
border-radius: 50%;
float: left;
}

.list-items li.active {
cursor: pointer;
margin-left: 50px;
list-style: none;
border: 3px solid #FF04FF;
background-color: #FF04FF;
border-radius: 50%;
float: left;
}

.list-item li:first-child:after {
cursor: initial;
position: absolute;
content: '';
width: 50px;
margin-top: -6px;
margin-left: 40px;
height: 50%;
border-bottom: 2px solid #D9D9D9;
z-index: 0;
}

.list-items li:after {
cursor: initial;
position: absolute;
content: '';
width: 50px;
margin-top: 0px;
margin-left: 15px;
height: 50%;
border-bottom: 2px solid #D9D9D9;
z-index: 0;
}

.list-item ul .actived:after {
border-bottom: 2px solid #FF04FF;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex justify-content-center timeline-background">
<div class="d-flex justify-content-center">
<section class="list-items">
<ul class="dots">
<li class="active"><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
</ul>
</section>
<div class="list-item">
<ul>
<li class="d-flex d-sm-flex d-md-flex d-lg-flex d-xl-flex justify-content-center align-items-center justify-content-sm-center align-items-sm-center justify-content-md-center align-items-md-center actived" href="#list1"><i class="icon ion-ios-arrow-back"></i></li>
<li class="d-flex justify-content-center align-items-center"><a class="item" href="#"></a><i class="icon ion-ios-arrow-forward"></i></li>
</ul>
</div>
</div>
</div>

现在它在到达 div 边缘时断开线!

最佳答案

非常感谢那些试图提供帮助的人,我真的很感激!我在这里发布我是如何解决这个问题的!从问题文本中,您可以将我卡住的代码与此处的最终代码进行比较。我所做的是添加 backpage 类,并为其设置宽度并 overflow hidden 和绝对位置,然后将 list-items 类位置更改为绝对位置并设置一个固定的宽度,而不是我只是调整元素在屏幕上的位置!!

这里是最终代码:

.timeline-background {
position: relative;
width: 100%;
height: 300px;
background-color: #F5F5F5;
padding: 0;
padding-top: 50px;
}

.backpage {
position: relative;
overflow: auto;
width: 450px;
}

.list-items {
position: absolute;
width: 2000px;
height: auto;
margin: 0;
padding: 0;
margin-top: 20px;
margin-left: -10px;
}

.list-item {
position: absolute;
width: 500px;
top: 0;
height: auto;
margin: 0;
padding: 0;
}

.list-items li {
position: relative;
}

.list-item li:first-child {
position: absolute;
left: 20px;
top: 63px;
cursor: pointer;
list-style: none;
width: 30px;
height: 30px;
background-color: #fff;
border: 3px solid #AD80FF;
color: #D9D9D9;
border-radius: 50%;
float: left;
}

.list-item li:last-child {
position: absolute;
right: -13px;
top: 63px;
cursor: pointer;
list-style: none;
width: 30px;
height: 30px;
margin-left: 50px;
background-color: #fff;
border: 3px solid #AD80FF;
color: #D9D9D9;
border-radius: 50%;
float: left;
}

.list-item li:last-child:hover {
color: #FF04FF;
}

.list-item li:first-child:hover {
color: #FF04FF;
}

.list-item .active {
}

.list-items li {
cursor: pointer;
margin-left: 50px;
list-style: none;
width: 15px;
height: 15px;
background-color: #fff;
border: 3px solid #D9D9D9;
margin-top: 0;
border-radius: 50%;
float: left;
}

.list-items li.active {
cursor: pointer;
margin-left: 50px;
list-style: none;
border: 3px solid #FF04FF;
background-color: #FF04FF;
border-radius: 50%;
float: left;
}

.list-items li:not(:last-child):after {
cursor: initial;
position: absolute;
content: '';
width: 50px;
margin-top: 0px;
margin-left: 12px;
height: 50%;
border-bottom: 2px solid #D9D9D9;
z-index: 0;
}

.list-items li:first-child:before {
cursor: initial;
position: absolute;
content: '';
width: 50px;
margin-top: 0px;
margin-left: -53px;
height: 50%;
border-bottom: 2px solid #D9D9D9;
z-index: 0;
}

.list-items li:last-child:after {
cursor: initial;
position: absolute;
content: '';
width: 50px;
margin-top: 0px;
margin-left: 12px;
height: 50%;
border-bottom: 2px dashed #D9D9D9;
z-index: 0;
}

.list-item ul .actived:after {
border-bottom: 2px solid #FF04FF;
}

.list-item ul .actived {
color: #FF04FF;
}

.dots {
width: 100%;
position: relative;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex d-xl-flex justify-content-center justify-content-xl-center timeline-background">
<div class="backpage">
<section class="list-items">
<ul class="dots">
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
<li><a class="item" href="#"></a></li>
</ul>
</section>
</div>
<div class="list-item">
<ul>
<li class="d-flex d-sm-flex d-md-flex d-lg-flex d-xl-flex justify-content-center align-items-center justify-content-sm-center align-items-sm-center justify-content-md-center align-items-md-center" href="#list1"><i class="icon ion-ios-arrow-back"></i></li>
<li class="d-flex justify-content-center align-items-center"><a class="item" href="#"></a><i class="icon ion-ios-arrow-forward"></i></li>
</ul>
</div>
</div>

再次,非常感谢!!

关于html - 添加元素时时间轴 slider 被压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57597504/

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