https://www.bootply.com/XzK3zrPhJJ
In this example, why is the Home button not marked red?
.navbar a:hover,
.navbar a:focus,
.navbar a:active {
color: red !important;
}
<nav class="navbar navbar-expand-lg">
<div class="collapse navbar-collapse">
<div class="nav navbar-nav">
Home
Links
About
</div>
</div>
</nav>
You shoud use not a:active but a.active
:after is a pseudo class. But you want to select a tags which also has .active class.
.navbar a:hover,
.navbar a:focus,
.navbar a.active {
color: red !important;
}
<nav class="navbar navbar-expand-lg">
<div class="collapse navbar-collapse">
<div class="nav navbar-nav">
Home
Links
About
</div>
</div>
</nav>
Use the css Class selectors
The CSS class selector matches elements based on the contents of their
class attribute.
.navbar a.active {
color: red;
}
<nav class="navbar navbar-expand-lg">
<div class="collapse navbar-collapse">
<div class="nav navbar-nav">
Home
Links
About
</div>
</div>
</nav>
keep in mind that The :hover CSS pseudo-class
The :hover CSS pseudo-class matches when the user interacts with an
element with a pointing device, but does not necessarily activate it.
It is generally triggered when the user hovers over an element with
the cursor (mouse pointer).
and avoid !important you can read more about !important_exception here
Why is it not active, but with active CLASS
instead of a:active use .active to reference, in this case you can also read more about the selector HERE
I think, it should be like this:
navbar a:hover {
color:red;
font-weight:bolder;
text-decoration:underline;
}
Related
I must be doing something unusual, as the related questions and answers I've found so far on Stack Overflow aren't working for me. I'm new to css, so the answer may be obvious.
I prefer the solution to avoid !important, and if possible, only apply to the site header (e.g. not anywhere else on the site; that is, only apply to content inside block with id="my-block").
Also, would like solution to work for all levels in the nav (first, second, etc.).
This is what I tried:
.navbar .navbar-default > li > a:hover {
background-color: #FFFF00;
color: #FF0000;
}
Here's my code that runs along the top of my site:
<nav id="my-block" class="navbar navbar-default navbar-static-top navbar-default-siteheader navbar-inner-siteheader">
<div class="container">
<div class="collapse navbar-collapse in" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Menu1<span class="caret"></span>
<ul class="dropdown-menu">
...
</ul>
</li>
<li class="dropdown">
Menu2<span class="caret"></span>
<ul class="dropdown-menu">
...
</ul>
</li>
</ul>
</div>
</div>
</nav>
Change
.navbar .navbar-default > li > a:hover
to
#my-block.navbar li a:hover
You can add your customize id in parent element like :-
<div **id="custom-nav-head"**>
<ul>
<li>Link</li>
</ul>
</div>
and then in css file, use below
**#custom-nav-head** .navbar .navbar-default > li > a:hover {
color: your color
}
if still its not work so then use !important property. Like :-
**#custom-nav-head** .navbar .navbar-default > li > a:hover {
color: your color **!important**;
}
Try this:
a.dropdown:hover{
background-color://whatever colour
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm fairly new to web development (by fairly new I mean I'm taking a class on it right now), and I had a nicely styled website with my own external style sheet linked and all sorts of nifty javascript built in. However while trying to make my site look even better I decided to try out some bootstrap designs for my nav bar and assumed I could just copy and paste what I had in my original style sheet into the bootstrap.css sheet and link that, and now all my style is gone. Can anyone explain why this would happen/if I'm just making some sort of rookie mistake? Thanks!
You have to place your custom style sheet under the bootstrap.css like so
<!-- Bootstrap Core CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.css" rel="stylesheet">
<!-- custom stylesheet -->
<link href="css/custom.css" rel="stylesheet">
It is because the HTML reads the css files from up to bottom. Always start with a bootstrap css and from there on you have to tweak inside your css file. So, if your adding a bootstrap nav, you have to make edits in your custom css to change the layout. Maybe you could add some code to be more specific what is going wrong.
Example of a tweak to bootstrap.css:
HTML of a navbar
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>HOME</li>
<li class="dropdown">
PORTFOLIO<span class="caret"></span>
<ul class="dropdown-menu">
<li>WEDDING</li>
<li>LOVE</li>
</ul>
</li>
<li class="dropdown">
ABOUT<span class="caret"></span>
<ul class="dropdown-menu">
<li>US</li>
</ul>
</li>
<li class="dropdown">
BLOG<span class="caret"></span>
<ul class="dropdown-menu">
<li>STORIES</li>
<li>ARCHIVE</li>
</ul>
</li>
<li>CONTACT</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Custom CSS tweaks
/* BOOTSTRAP TWEAKS */
.navbar-default {
background: none;
border: none;
}
.navbar-default .navbar-nav li a {
color: #9c9c9c;
}
.caret {
border-top-color: #9c9c9c;
border-bottom-color: #9c9c9c;
}
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
.dropdown-menu > li > a:hover, .dropdown-menu > li > a:focus {
color: black;
text-decoration: underline #9c9c9c;
background: none;
}
.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:hover, .navbar-default .navbar-nav > .open > a:focus {
color: #555555;
background: none;
}
.dropdown-menu {
list-style: none;
background: none;
border: none;
-webkit-box-shadow:none;
box-shadow: none;
}
I was wondering, because when I click on a dropdown menu the thickness of the li navbar elements decreases. Using the standard layout:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img class="logo" src="imgs/logo.png">
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
**<li><span class="navli">SERVICES</span></li>
<li><span class="navli">OUR WORK</span></li>
<li><span class="navli">ABOUT</span></li>**
<li class="dropdown">
<img src="imgs/english.png" style="padding-right:3px;margin-left:-5px;"><span class="caret"></span>
<ul class="dropdown-menu">
<li><img src="imgs/deutsch.png"> Deutsch</li>
<li role="separator" class="divider"></li>
<li><img src="imgs/espanol.png"> EspaƱol</li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container -->
</nav>
Does anybody know where the CSS is for this.
And another question:
Is there a way of seeing the CSS changes being applied, when an action occurs? Maybe I can try to find out that way.
Thanks in advance
That would be the following snippet if you are using the 'default navbar'
(Line 4498 in bootstrap.css)
.navbar-default .navbar-nav > li > a {
color: #777;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
color: #333;
background-color: transparent;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
color: #555;
background-color: #e7e7e7;
}
.navbar-default .navbar-nav > .disabled > a,
.navbar-default .navbar-nav > .disabled > a:hover,
.navbar-default .navbar-nav > .disabled > a:focus {
color: #ccc;
background-color: transparent;
}
Is there a way of seeing the CSS changes being applied, when an action occurs? Maybe I can try to find out that way.
I suggest learning how to use your browser's developer tools. DevTools are great for examining, editing and debugging. Below are links to the How tos for IE, Firefox and Chrome. You can also Google search for your specific browser to learn how to use their devtool (If it's available).
Internet Explorer - https://msdn.microsoft.com/en-us/library/gg589507(v=vs.85).aspx
Google Chrome - https://developers.google.com/web/tools/chrome-devtools/iterate/inspect-styles/basics
Mozilla Firefox - https://developer.mozilla.org/en-US/docs/Tools
Thanks for the answers, I tried finding it with the developer tools.
Changing the color unfortunately doesn't do the trick. It is more and issue of the width, that changes when the dropdown is active and the other li > a elements react.
How do I make my font color white, on the current nav bar class?
For example, when I click on a link on the nav it adds a class="current" to that link.
But I'm having trouble styling that particular link.
Here's the HTML:
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-loggedin-nav mineul pull-right" style="font-size:22px;margin-top:7px; color:white;">
<li>
<a class="current" href="/">
</li>
<li>
Here's my CSS attempt which is way off:
.nav > li > a .current {
color: white;
}
.nav > li > a.current
Just a small change. The space between "a" and ".current" makes it think .current is a new element.
No space between the anchor element selector and the class name selector:
.nav > li > a.current {
color: white;
}
HTML
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-loggedin-nav mineul pull-right" style="font-size:22px;margin-top:7px; color:white;">
<li>
<a class="current" href="/">Text Here</a>
</li>
<li>
CSS
a.current {
color: white;
}
This may be simple, however I can't seem to accomplish what I need.
Basically, I want the colour to change to something else rather than bootstrap's default blue when the page in question is in active.
I have tried many different css, but this is my current:
ul.nav a:active {
background-color: #3366CC !important;
}
The navbar that im using is as followed:
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" 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>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav nav-pills nav-justified fixed-top">
<li class="active">Home</li>
etc
Is there a simple CSS rule that I'm missing, the colours change quite freely for my other menu needs, such as:
ul.nav {
padding: 5px;
}
ul.nav li a {
color: #fff;
}
ul.nav li a:hover{
color: #CC0033 !important;
}
ul.nav a:hover {
background-color: #fff !important;
}
Any help will be appreciated!
You just need to add the color to the a tag inside the li with the active class
ul.nav li.active a {
background-color: #3366CC !important;
}
The :active pseudo-class only matches when, for example, the user is in the process of clicking on the link:
https://developer.mozilla.org/en-US/docs/Web/CSS/:active
It does not indicate which page is active.
In Bootstrap the page/section that is currently active is signaled by an active class on the li. In Bootstrap 3, try:
.nav > .active {
background-color: #3366CC;
}
Use Inspect Element to find out what style is actually being applied, so you can properly override it.