【发布时间】:2023-03-24 06:10:01
【问题描述】:
我是前端编码的新手。我刚刚通过复制此处http://kodhus.com/newsite/step-progress-bar-css-only 的css 在我的网页中添加了一个progessa 栏。现在我需要将球中的数字替换为“选中”图标。我有一张选中图标的 jpg 图片,但我没有努力展示它:
.progressbar li:before {
width: 30px;
height: 30px;
/*content:url('checked2.jpg');*/
/*content: counter(step); */
content: 'v';
/*class: glyphicon glyphicon-ok;
counter-increment: step;*/
line-height: 30px;
border: 2px solid #7d7d7d;
display: block;
text-align: center;
margin: 0 auto 10px auto;
border-radius: 50%;
background-color: white;
}
我尝试将我的 jpg 存储到 django 根目录、静态目录和模板目录中,但其中没有一个可以工作。运行上面的代码,我的球中出现了“v”,这对所有人来说都是如此。
把上面的定义改成
.progressbar li:before {
width: 30px;
height: 30px;
content: '';
counter-increment: step;
line-height: 27px;
border: 2px solid #7d7d7d;
display: block;
text-align: center;
margin: 0 auto 10px auto;
border-radius: 50%;
background-color: white;
background: (https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTLB-KSrRyq61FczWe9AUdEdz2GJfs51oNKuiF_c3dfkRH23Ii9);
background-size: cover;
background-repeat-y: no-repeat;
background-position: center center;
/* z-index: 1111; */
}
我设法让检查图标进入每个圆圈(li 元素)。
但实际上我只需要检查某些 li 元素。 我在 jquery 中尝试了以下操作,但它根本不起作用(它似乎绘制了一个新圆圈而不是修改现有的圆圈,并且检查的图像不再适合圆圈)
修改前的 CSS:
.progressbar li:before {
width: 30px;
height: 30px;
content: counter(step);
counter-increment: step;
line-height: 30px;
border: 2px solid #7d7d7d;
display: block;
text-align: center;
margin: 0 auto 10px auto;
border-radius: 50%;
background-color: white;
}
html:
<div class="container">
<ul class="progressbar">
<li id="first">login</li>
<li id="second" class="active">choose interest</li>
<li id="third">add friends</li>
<li id="fourth">View map</li>
</ul>
jquery 将检查符号添加到第一个 li 元素中
$("#first").css('content','');
$("#first").css('background', '(https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTLB-KSrRyq61FczWe9AUdEdz2GJfs51oNKuiF_c3dfkRH23Ii9)');
$("#first").css('background-size','cover');
$("#first").css('background-repeat-y','no-repeat');
$("#first").css('background-position','center center');
【问题讨论】:
-
尝试添加位置:绝对;并添加父 div 位置:相对
-
尝试使用“the progressbar li”类。然后背景图片:img url;如果您的图像位于本地项目中,您可能需要 ./[img-name] 而不仅仅是 [img-name]。点表示 url 路径后退 1 步,/ 表示前移一步。如果它超过 2 步,则使用 img 的完整 url。从 C/D 驱动器。
-
请做一个 JSFiddle here
-
Nvm 对不起我的评论,忘记进度条 li 类。你做对了。关于背景图片,使用 content: url();像你一样,但与我解释背景图像的方式相同。