javascript - CSS中的响应式部分指示器
问题描述
我正在构建一个自定义场景指示器,向用户指示他目前在哪个场景中,到目前为止 javascript 是好的,我的问题是 css 我希望我的场景指示器至少对大于中等屏幕的屏幕做出响应。这是我的 html 代码:
<div class="text-center scroll-navigation-indicator">
<span class="active-index"></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span class="last"></span>
</div>
这是我的 scss 代码:
.scroll-navigation-indicator {
position: fixed;
top: 0;
padding: 25px 0;
left: 50%;
z-index: 1500;
box-sizing: content-box;
background-color: transparent;
transform: translateX(-50%);
inline-size: fit-content;
width: 1200px;
display: flex;
justify-content: space-between;
span {
width: 20px;
height: 20px;
background-color: black;
display: inline-block;
position: relative;
border-radius: 50%;
cursor: pointer;
margin: 0 10px;
}
span:after {
content: '...............................';
margin-left: 10px;
position: absolute;
top: -3px;
left: 100%;
}
span:last-of-type:after {
content: ""
}
span.active-index {
background-color: black;
width: 30px;
height: 30px;
position: relative;
top: -5px;
}
span.active-index:after {
content: "...............................";
top: 3px;
}
span.active-index.last:after {
content: "";
}
span.active-index:before {
border-radius: 50%;
padding: 5px;
border: 2px solid black;
position: absolute;
content: '';
top: -6px;
left: -6px;
bottom: -6px;
right: -6px;
}
}
这是在codepen中编译的结果。我的问题是我将 div 容器设置为,width:1200px
因为它使每个span:after
显示都正确。如果有任何其他解决方案,我将很高兴听到并实施它。祝大家编码愉快。
解决方案
通过使用display: flex
和flex-wrap: nowrap
添加一些CSS,我们将实现这一点。请看下面的片段。
.scroll-navigation-indicator {
display: flex;
flex-wrap: nowrap; /* Specifies that the flexible items will not wrap */
margin: 30px 0;
overflow: hidden;
color: #333;
padding:10px 0;
}
.scroll-navigation-indicator li {
position: relative;
list-style-type: none;
flex: 1; /* Let all the flexible items be the same length, regardless of its content */
}
.scroll-navigation-indicator li:before {
width: 20px;
height: 20px;
content: '';
display: block;
background: #000;
border-radius: 50%;
margin: auto;
padding: 0px;
border: 4px solid #fff; /* to add space between dots and border */
}
.scroll-navigation-indicator li:after {
content: '';
width: 100%;
border-bottom: 2px dashed #000;
position: absolute;
top: 50%; /* to vertically center the border */
transform: translateY(-50%); /* to vertically center the border */
z-index: -1;
}
.scroll-navigation-indicator li:after {
left: 50%
}
.scroll-navigation-indicator li:last-child:after {
content: none;
}
.scroll-navigation-indicator li.active-index:before{
box-shadow: inset 0px 0px 0px 4px transparent, 0px 0px 0px 2px #000; /* to have circle for active-index*/
}
<ul class="scroll-navigation-indicator">
<li class="active-index">
</li>
<li class="active-index">
</li>
<li class="">
</li>
<li class="">
</li>
<li class="">
</li>
<li class="">
</li>
<li class="">
</li>
<li class="">
</li>
</ul>
推荐阅读
- c - 分配超出范围的值时,静态分配的数组不会溢出
- php - 如何调试错误“已弃用:curl_setopt():”
- typescript - 打字稿是类型检查不包含的文件吗?
- tcl - tcl 脚本中的命令名无效
- c - 以结构为输入参数的 C 代码的 FMU 导出
- oracle - pl/sql 函数中的多个查询
- data-structures - 如何在不需要分配新变量的情况下为链表实现前置?
- javascript - Reactjs 组件`this.state` 未定义
- opencv - 使用 OpenCV4Android 还是运行基于 Python 的 openCV 代码?
- linux - 如何制作一个可以使用 shell 脚本过滤文件的提示过滤器?