[英]css selector needed to change color of text in dropdown
I am trying to change the color of the links used for the phone numbers in the dropdown- menu ul part. 我正在尝试更改下拉菜单ul部分中用于电话号码的链接的颜色。 Have tried tons of different selectors but nothing is working! 尝试了很多不同的选择器,但没有任何效果! I'm using bootstrap 3. Anybody and ideas?i chnaged the font size using the selector .dropdown-menu li a but the color of the font would not change. 我正在使用引导程序3。有人和想法吗?我使用选择器.dropdown-menu li a更改了字体大小,但是字体的颜色不会改变。 Any help would be great 任何帮助都会很棒
<div id="desktop" class="navbar-brand">
<a class="numbers" href="tel:018151515">018 15 15 15</a>
</div>
<div id="call">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" >
<span class="glyphicon glyphicon-earphone" id="earphone">`enter code here`</span>
<b class="caret" ></b>
</a>
<ul class="dropdown-menu">
<li>
<a class="numbers" href="tel:018151515">018 15 15 15</a>
</li>
<li class="divider">
<a href="tel:018151515"></a>
</li>
<li class="header">
<a class="numbers" href="tel:018151515">Mobile Numbers</a>
</li>
<li class="divider">
<a href="tel:018151515"></a>
</li>
<li>
<a class="numbers" href="tel:018151515">085 111 1111</a>
</li>
<li>
<a class="numbers" href="tel:018151515">086 222 2222</a>
</li>
<li>
<a class="numbers" href="tel:018151515">087 333 3333</a>
</li>
</ul>
</li>
</ul>
</div>
Use This CSS: 使用此CSS:
a[href*="tel:"] { color: red; }
It will text color red of all anchors who has href with tel: 它将使用tel href的所有锚点的文本显示为红色:
When a valid style isn't being applied, I've found two common causes: 当没有应用有效的样式时,我发现了两个常见原因:
In your case, since the font-size is being applied, I'm guessing 2 rather than 1. So when you correctly select with .dropdown-menu li
you're able to set the font-size and it applies to the text within the li tag and down to the link text as well. 在您的情况下,因为正在应用字体大小,所以我猜是2而不是1。因此,当您使用.dropdown-menu li
正确选择时,您可以设置字体大小并将其应用于文本li标签以及链接文本。 However, when you apply the color to the li
tag, it is overridden by a color setting on the a
tag because the a
tag is more specific. 但是,当你申请颜色与li
标签,它是由一种颜色设置覆盖在a
因为标签a
标签是更具体的。
Specificity are the rules which determine what CSS is applied to what part of a web page. 特殊性是确定将CSS应用于网页的哪个部分的规则。 There are many good articles about it, including this one: http://css-tricks.com/specifics-on-css-specificity/ 关于它,有很多很好的文章,包括这篇文章: http : //css-tricks.com/specifics-on-css-specificity/
If it is the a
tag which is causing the problem, you need a selector that will be more specific than the a
tag. 如果它是a
,这是造成问题的标签,你需要一个选择,这将是比更具体的a
标签。 ul.dropdown-menu > li > a.number
should work, and if it isn't specific enough, you can match against the href
part of the a
with something like: ul.dropdown-menu > li > a[href^="tel"].numbers
. ul.dropdown-menu > li > a.number
应该工作,如果它不够具体,可以匹配对href
的一部分a
喜欢的东西: ul.dropdown-menu > li > a[href^="tel"].numbers
。 This is slightly more efficient than the *=
matching will will find "tel" anywhere in the href. 这比*=
匹配将在href的任何位置找到“ tel”的效率略高。
If I could see your CSS I'd be able to confirm my guess and solution. 如果可以看到您的CSS,则可以确认我的猜测和解决方案。 Maybe try a jsfiddle next time? 也许下次尝试jsfiddle ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.