简体   繁体   English

字体真棒的CSS样式无法正常工作

[英]css styling of font-awesome not working properly

I added font-awesome icons to my navbar and styled it with css. 我在导航栏中添加了超棒的字体图标,并使用CSS设置了样式。 All works well except on the link with the dropdown list - once clicked - it shows two icons instead of only one (see screenshot). 除带有下拉列表的链接外,所有其他选项均运行良好,单击该链接后,它将显示两个图标,而不是一个图标(请参见屏幕截图)。 One is properly placed and the other one appears below the word 'link' and above the dropdown menu. 一个放置正确,另一个显示在“链接”下方和下拉菜单上方。

在此处输入图片说明

Here is the html code: 这是html代码:

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav navbar-right">
    <li class="active"><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
    <li><a href="#">Link</a></li>
    <li class="dropdown">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
  </ul>

and here the css code: 这里的CSS代码:

ul li a:before {
    font-family: "FontAwesome";
    content: "\f067";
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    text-align: center;
    color: #FFF;
    width: 100%;
    height: 100%;
    margin-top: -26px;  
}

I would greatly appreciate it if someone could tell me how to get rid of the icon (=white cross) under the word dropdown. 如果有人能告诉我如何摆脱下拉菜单下的图标(=白叉),我将不胜感激。

Thanks in advance for your help. 在此先感谢您的帮助。

The thing is that your CSS is applying to way more that you want it to. 问题是您的CSS正在应用到您想要的更多方式。 Your imbedded UL is also triggering your CSS rules. 您的嵌入式UL也会触发您的CSS规则。 You probably have even more white crosses appearing but you can't see them because your background is white.You should apply a class to the links that you want to have your white cross and then apply the css rules only to that class. 您可能会出现更多的白色十字,但由于背景为白色,因此您看不到它们。您应该将一个类应用于您想要拥有白色十字的链接,然后仅将CSS规则应用于该类。

I think that you are seeing extra + icons because your css selector is incorrect. 我认为您看到的是多余的+图标,因为您的CSS选择器不正确。 In actual fact you are probably getting 5 extra + icons (1 for each <a> in the dropdown menu). 实际上,您可能会额外获得5个+图标(下拉菜单中的每个<a> 1个)。

To solve this you need to target only the <a> 's under the navbars <ul> not the dropdowns <ul> 为了解决这个问题,您只需要定位导航栏<ul>下的<a>而不是下拉菜单<ul>

try this selector: ul > li > a:before 尝试以下选择器: ul > li > a:before

EDIT 编辑

I have forked and corrected your bootply below: 我在以下分叉并纠正了您的启动问题:

http://www.bootply.com/OSTDVMekNE http://www.bootply.com/OSTDVMekNE

The issue was on line 52 of your css (in bootply) 问题出在CSS的第52行(在bootply中)

.cross a:before, .cross:hover > a:before { 

should have been 本来应该

.cross > a:before, .cross:hover > a:before { 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM