html - Change caret color only if hovered or focused -
i trying have caret color black if not hovered or focused , white if hovered or focused. have tried using :hover
, :focus
on caret seem have no effect.
html:
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> menu caret<i class="caret"></i></a> <ul class="dropdown-menu"> <li> <a href="#"> sub menu </a> </li> </ul> </li> </ul>
css:
.navbar .nav li.dropdown > .dropdown-toggle .caret { border-top-color: #fff; border-bottom-color: #fff; } @media (max-width: 767px) { .navbar-default .navbar-nav > li > { background-color: #fff; color: #333333 !important; } .navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { color: #fff !important; background: #2d3335; } .navbar-default .navbar-nav .open .dropdown-menu > li > { color: #ecf0f1; } .navbar-default .navbar-nav .open .dropdown-menu > li > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > li > a:focus { color: #ffffff; } .navbar-default .navbar-nav .open .dropdown-menu > .active > a, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus { color: #ffffff; background-color: #2d3335; } }
i have tried doing:
.navbar .nav li.dropdown > .dropdown-toggle .caret { border-top-color: #000; border-bottom-color: #000; }
and inside media query:
.navbar .nav li.dropdown > .dropdown-toggle .caret:hover, .navbar .nav li.dropdown > .dropdown-toggle .caret:focus { border-top-color: #fff; border-bottom-color: #fff; }
the :hover
should applied anchor element, not .caret
.
use instead:
.navbar .nav li.dropdown > .dropdown-toggle .caret { border-top-color: #333333; border-bottom-color: #333333; } .navbar .nav li.dropdown > .dropdown-toggle:hover .caret, .navbar .nav li.dropdown > .dropdown-toggle:focus .caret { border-top-color: #fff; border-bottom-color: #fff; }
code snippet:
@media (max-width: 767px) { .navbar-default .navbar-nav > li > { background-color: #fff; color: #333333 !important; } .navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { color: #fff !important; background-color: #2d3335 !important; } .navbar .nav li.dropdown > .dropdown-toggle .caret { border-top-color: #333333; border-bottom-color: #333333; } .navbar .nav li.dropdown > .dropdown-toggle:hover .caret, .navbar .nav li.dropdown > .dropdown-toggle:focus .caret { border-top-color: #fff; border-bottom-color: #fff; } .navbar-default .navbar-nav .open .dropdown-menu > li > { color: #ecf0f1; } .navbar-default .navbar-nav .open .dropdown-menu > li > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > li > a:focus { color: #ffffff; } .navbar-default .navbar-nav .open .dropdown-menu > .active > a, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:hover, .navbar-default .navbar-nav .open .dropdown-menu > .active > a:focus { color: #ffffff; background-color: #2d3335; } }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> <link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" /> <div class="nav-gradient"> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav"> <li class="dropdown"> <a href="/domains/view/high-end-price" class="dropdown-toggle" data-toggle="dropdown"> menu caret<i class="caret"></i></a> <ul class="dropdown-menu"> <li> <a href="/domains/view/new-listings"> sub menu </a> </li> </ul> </li> </ul> </div> </div> </nav> </div>
Comments
Post a Comment