简体   繁体   English

在活动类css引导程序中添加背景图像

[英]add background image in active class css bootstrap

I am using bootstrap tabs. 我正在使用引导程序选项卡。 I want to use a down arrow for active class on tabs. 我想在选项卡上使用向下箭头进行活动课程。

<ul class="nav nav-tabs" style="font-size:20px;">
                  <li><a  class="active" data-toggle="tab" href="#menu1"><span class="glyphicon glyphicon-sound-dolby"></span></a></li>
                  <li><a data-toggle="tab" href="#menu2"><span class="glyphicon glyphicon-send"></span></a></li>
                  <li><a data-toggle="tab" href="#menu3"><span class="glyphicon glyphicon-earphone"></span></a></li>
                  <li><a data-toggle="tab" href="#menu4"><span class="glyphicon glyphicon-send"></span></a></li>
                </ul>

Here is css of active class. 这是活动类的CSS。

.nav-tabs>li.active>a, .nav-tabs>li.active>a:focus, .nav-tabs>li.active>a:hover {
    color: #555;
    cursor: default;
    background-color: #fff;
    background: url('../image/down.png') no-repeat !important;
    border: 1px solid #ddd;
    border-bottom-color: transparent;
}

Right now its just displaying white background for active class. 现在,它只显示活动课程的白色背景。 But not the image. 但不是图像。 Kindly help me. 请帮助我。 Thank you 谢谢

The problem in css class. CSS类中的问题。 You assigned it to anappropriate selector. 您已将其分配给适当的选择器。 In html class assigned to tag, but in css to 在分配给标记的html类中,但在CSS中

  • . You need to wright correct css rule. 您需要修改正确的CSS规则。 So your code will looks like this: 因此您的代码将如下所示:

     .nav-tabs>li>a.active { background: #fff url('../image/down.png') right center no-repeat ; } 
  • Alternatively you can try this-- 另外,您也可以尝试-

    Working snippet 工作片段

      .nav li.active { cursor: default; background: url('https://www.w3schools.com/css/img_fjords.jpg') no-repeat !important; background-size: contain; border: 1px solid #ddd; border-bottom-color: transparent; } .nav-tabs>li.active>a, .nav-tabs>li.active>a:focus, .nav-tabs>li.active>a:hover { background-color: transparent !important; } 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <ul class="nav nav-tabs" style="font-size:20px;"> <li><a class="active" data-toggle="tab" href="#menu1"><span class="glyphicon glyphicon-sound-dolby"></span></a></li> <li><a data-toggle="tab" href="#menu2"><span class="glyphicon glyphicon-send"></span></a></li> <li><a data-toggle="tab" href="#menu3"><span class="glyphicon glyphicon-earphone"></span></a></li> <li><a data-toggle="tab" href="#menu4"><span class="glyphicon glyphicon-send"></span></a></li> </ul> 

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

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