[英]Styling anchor and li elements css
I have a progress bar. 我有一个进度条。 It works well, but my concern is for the style.
它运作良好,但我关注的是风格。 Some lines are displayed and I don't know why.
显示一些行,我不知道为什么。 In the screenshot below you can see lines between numbers.
在下面的屏幕截图中,您可以看到数字之间的线。 Any ideas?
有任何想法吗?
My jsfiddle: JSFIDDLE 我的jsfiddle: JSFIDDLE
My code: 我的代码:
ol.progtrckr { margin: 0; padding: 0; list-style-type: none; } ol.progtrckr li { display: inline-block; text-align: center; line-height: 3em; } ol.progtrckr[data-progtrckr-steps="4"] li { width: 15%; } ol.progtrckr li.progtrckr-done { color: black; padding-right: 12px; border-bottom: 4px solid green; } ol.progtrckr li.progtrckr-todo { color: silver; padding-right: 12px; border-bottom: 4px solid silver; } ol.progtrckr li:after { content: "\\00a0\\00a0"; } ol.progtrckr li:before { position: relative; bottom: -2.5em; float: left; left: 50%; line-height: 1em; } ol.progtrckr li.progtrckr-done:before { content: "\\2713"; color: white; background-color: green; height: 1.2em; width: 1.2em; line-height: 1.2em; border: none; border-radius: 1.2em; } ol.progtrckr li.progtrckr-todo:before { content: "\\039F"; color: silver; background-color: white; font-size: 1.5em; bottom: -1.6em; }
<ol class="progtrckr" data-progtrckr-steps=""> <a href="#" > <li class="progtrckr-done ">1 </li> </a> <a href="#"> <li class="progtrckr-done">2 </li> </a> <a href="#"> <li class="progtrckr-done">3 </li> </a> <a href="#"> <li class="progtrckr-todo">4 </li> </a> </ol>
Please apply text-decoration:none for anchor under with class "progtrckr" this line will be disappear or add below css in your stylesheet file - 请使用text-decoration:none for anchor with class“progtrckr”此行将消失或在样式表文件中添加以下css -
ol.progtrckr>a {
text-decoration:none;
}
You using "display: inline-block" for "ol.progtrckr li", so these elements behave like inline elements but they have the space. 您使用“display:inline-block”表示“ol.progtrckr li”,因此这些元素的行为类似于内联元素,但它们具有空格。 So you should use "float:left" instead of "display: inline-block".
所以你应该使用“float:left”而不是“display:inline-block”。 You also should use "clearfix" for "ol" element.
您还应该为“ol”元素使用“clearfix”。 For example: add ".clerfix" class to "ol" element and use the following css:
例如:将“.clerfix”类添加到“ol”元素并使用以下css:
.clearfix:after {
content: ".";3
display: block;
height: 0;
clear: both;
visibility: hidden;
}
You have to put your "li" tags before your "a" tags, like this: 你必须在“a”标签之前加上“li”标签,如下所示:
<ol class="progtrckr" data-progtrckr-steps="">
<li class="progtrckr-done"><a href="#">1</a></li>
<li class="progtrckr-done"><a href="#">2</a></li>
<li class="progtrckr-done"><a href="#">3</a></li>
<li class="progtrckr-done"><a href="#">4</a></li>
</ol>
You are linking the entire <li>
element while you should link only the value inside it: 您链接整个
<li>
元素,而您应该只链接其中的值:
<ol class="progtrckr" data-progtrckr-steps="">
<li class="progtrckr-done "><a href="#" >1</a></li>
<li class="progtrckr-done "><a href="#" >2</a></li>
<li class="progtrckr-done "><a href="#" >3</a></li>
<li class="progtrckr-done "><a href="#" >4</a></li>
</ol>
Here is the updated JSFiddle I also added a padding:0
here: 这是更新的JSFiddle我还在这里添加了一个
padding:0
:
ol.progtrckr li.progtrckr-done {
color: black;
padding-right: 12px;
border-bottom: 4px solid green;
padding: 0;
}
It's default text decoration on the <a>
element. 它是
<a>
元素上的默认文本修饰。
Use: 使用:
a{
text-decoration: none;
}
Add 加
a:link {
text-decoration: none;
}
(Links are underlined by default in many browsers) (许多浏览器默认为链接加下划线)
Addition: Or, if you want to keep the underline in your regular links, write this instead, and to be safe, include the other link states too: 增加:或者,如果您想在常规链接中保留下划线,请改为编写,为安全起见,请包含其他链接状态:
.progtrckr-done a:link,
.progtrckr-done a:hover,
.progtrckr-done a:active,
.progtrckr-done a:visited {
text-decoration: none;
}
Updated fiddle here: https://jsfiddle.net/aLwgrym8/63/ 更新了小提琴: https : //jsfiddle.net/aLwgrym8/63/
You simply need to add text-decoration: none to the anchor elements: 您只需要在anchor元素中添加text-decoration:none:
ol.progtrckr > a {
text-decoration: none;
}
Alternatively, you could move the anchor elements within the <li>
's as opposed to the other way around which you're currently doing. 或者,你可以移动
<li>
的锚元素,而不是你当前正在做的另一种方式。 Updated fiddle for this here: https://jsfiddle.net/aLwgrym8/65/ 这里更新了小提琴: https : //jsfiddle.net/aLwgrym8/65/
HTML: HTML:
<ol class="progtrckr" data-progtrckr-steps="">
<li class="progtrckr-done "><a href="#" >1</a></li>
<li class="progtrckr-done"><a href="#">2</a></li>
<li class="progtrckr-done"><a href="#">3</a></li>
<li class="progtrckr-todo"><a href="#">4</a></li>
</ol>
CSS: CSS:
ol.progtrckr li > a {
text-decoration: none;
color: #000;
}
Note that you have spaces between your closing </li>
tags and the closing </a>
tags. 请注意,在结束
</li>
标记和结束</a>
标记之间有空格。
<li class="progtrckr-done">2 </li> </a>
If you remove these, all the above actions won't be necessary at all, because there's nothing to underline in the links. 如果删除这些,则根本不需要上述所有操作,因为链接中没有任何下划线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.