第二个元素的css,javascript-在不同的CSS样式属性中给第二个元素

您需要使用.progressbar li:nth-​​child(2n)来定位其他所有li元素,然后需要将整个伪元素向上移动,然后将线和圆(:before和:after)向下移动.如果您没有将文本,行和圆全部都附加到同一元素/伪元素,这将容易得多.

查看代码段:

var progressBar = {

Bar: $('#progress-bar'),Reset: function() {

if (this.Bar) {

// this.Bar.find('li').addClass('active');

}

},Next: function() {

$('#progress-bar li:not(.active):first').addClass('active');

},Back: function() {

$('#progress-bar li.active:last').removeClass('active');

}

}

progressBar.Reset();

$("#Next").on('click',function() {

progressBar.Next();

})

$("#Back").on('click',function() {

progressBar.Back();

})

$("#Reset").on('click',function() {

progressBar.Reset();

})

.progressbar {

margin: 50px 0 50px 0;

counter-reset: step;

}

.progressbar li {

width: 12.5%;

list-style-type: none;

float: left;

font-size: 12px;

position: relative;

text-align: center;

text-transform: uppercase;

color: #555555;

}

.progressbar li:before {

position: relative;

width: 15px;

height: 15px;

content: '';

line-height: 30px;

border: 2px solid #555555;

background-color: #555555;

display: block;

text-align: center;

margin: 0 auto 10px auto;

border-radius: 50%;

transition: all .8s;

}

.progressbar li:after {

width: 100%;

height: 2px;

content: '';

position: absolute;

background-color: #555555;

top: 7px;

left: -50%;

z-index: -1;

transition: all .8s;

}

.progressbar li:first-child:after {

content: none;

}

.progressbar li.active:before {

border-color: #55b776;

background-color: #55b776;

transition: all .8s;

}

.progressbar li.active:after {

background-color: #55b776;

transition: all .8s;

}

.btn {

background-color: #55b776;

margin: 5px;

width: 75px;

color: white;

}

.btn:hover {

color: white;

}

.btn:focus {

color: white;

}

.btn-container {

display: flex;

justify-content: center;

width: 100%;

position: absolute;

bottom: 0;

}

body {

background-color: #f7f7f7;

}

.progressbar li:nth-child(2n) {

top: -50px;

}

.progressbar li:nth-child(2n):before {

top: 50px;

}

.progressbar li:nth-child(2n):after {

top: 57px;

}

Simple Step Progress Bar
  • Art
  • daten
  • zeit
  • ort
  • Pdf
  • Bilder
  • INFO
  • Bezahlen

Next

Back

Reset

以下CSS规则可以解决问题:

.progressbar li:nth-child(2n) {

top: -50px;

}

.progressbar li:nth-child(2n):after {

top: 57px;

}

.progressbar li:nth-child(2n):before {

top: 50px;

}

CSS(层叠样式表)主要用于控制网页文档的内容呈现方式,比如字体、颜色、布局等。在CSS,并没有直接提供选择特定序号的元素的选择器,例如选择第2个或第3个元素。 然而,你可以通过JavaScript或者伪类选择器间接实现这个功能。下面将分别给出这两种方法的示例: ### 使用JavaScript 你可以使用JavaScript动态地查找并操作DOM元素。假设你想获取第一个到第三个`<p>`标签的内容,并给它们添加不同的类名,可以这样做: ```javascript const paragraphs = document.getElementsByTagName('p'); for (let i = 0; i < paragraphs.length; i++) { if (i >= 2) break; paragraphs[i].classList.add('selected'); } ``` 在这个例子,我们首先获取所有`<p>`标签,然后遍历它们,当索引大于等于2时停止循环,并为前三个`<p>`标签添加了`selected`类。 ### 使用伪类选择器 如果目标元素有明确的父元素结构,且你想要选择基于该结构的特定元素,则可以利用伪类选择器。这里有一个例子,假设你需要选择某个`.container` div内部的所有`div`元素的第2个或第3个: HTML: ```html <div class="container"> <div>内容1</div> <div class="selected">内容2</div> <div>内容3</div> <!-- 更多div... --> </div> ``` CSS: ```css .selected { /* 应用到选择的元素的样式 */ } ``` 在这个例子,`.selected`类只应用到了`.container`内部的第二个`div`上,因为它是我们显式标记的那个。请注意,这依赖于特定的HTML结构,并不一定适用于所有情况,特别是当你需要处理更复杂的结构时。 ### 相关问题: 1. CSS如何选择所有段落标签的第一个元素? 2. 在JavaScript如何通过类名筛选DOM元素集合? 3. 当我们需要操作页面上元素的顺序发生变化时,如何保证CSS规则依然指向正确的元素?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值