BootStrap Dropdowns Not Being Styled Properly With navbar-inverse - html

I am trying to make a dropdown with the properties of navbar-inverse and on hover. I have the on hover problem fixed, it is the navbar-inverse I can not figure out. I have searched the internet and found if you used this code
.inverse-dropdown {
background-color: #222;
border-color: #080808;
&>li>a{
color: #999;
&:hover{
color: #fff;
background-color: #000;
}
}
}
it would make the dropdown color what I wanted, but the text remained very hard to see. I have tried changing the color tag to make the text what I wanted but it did not change anything. With that code my dropdown looks like this:
As you can see if you look at the image, the text is hard to read. Can someone please help me I have been trying to do this for days.
For reference this is all code that goes with the dropdown:
HTML:
<li class="dropdown">
<i class="fa fa-group"></i> Our Staff
<ul class="dropdown-menu inverse-dropdown text-center">
<li>Employee Login</li>
</ul>
</li>
CSS:
.dropdown:hover .dropdown-menu {
display: block;
}
.inverse-dropdown {
background-color: #222;
border-color: #080808;
&>li>a{
color: #999;
&:hover{
color: #fff;
background-color: #000;
}
}
}

I found this:
.navbar-default .navbar-nav .open .dropdown-menu>li>a, .navbar-default .navbar-nav .open
.dropdown-menu {
background-color: #222;
color:#fff;
}
Also, could it be that the color you see is the "visited" version of the link? Could you post your whole navbar?

.dropdown-menu.menu-inverse {
background-color: #222;
border-color: #080808;
}
.dropdown-menu.menu-inverse li > a {
color: #9d9d9d !important;
}
.dropdown-menu.menu-inverse ul > li > a:hover {
color: #fff;
background-color: #000;
}
.dropdown-menu.menu-inverse li.divider {
background-color: #000;
}
This CSS is just compiled version of LESS from #CalmKai's answer (which is straight off the GitHub issue).
My apps show the username in the top navbar, so inverse for it too:
.navbar-inverse #appMenuUsername {
color: #9d9d9d
}

Related

Overwriting an anchor tag styling in css bootstrap

I am want my active link to be red:
nav class="navbar navbar-inverse">
<div class="container col-1 col-sm-12">
<ul class="nav">
<li class="<%= 'active' if current_page?(squad_path) %>"><%= link_to("squad", squad_path)%></li>
<li class=" <%= 'active' if current_page?(album_path) %>"><%= link_to("album", album_path)%></li>
...
When I inspect the page, the li tag is active but doesn't change the color on the site. The hover is working fine changing by color.
This is my CSS code:
.nav li a{
display: inline-block;
padding-right: 8px;
padding-left: 8px;
color: #fff;
margin-bottom: 3px;
margin-top: 3px;
font-size: 40px;
font-family: "Germanica";
}
.nav li a:hover{
text-decoration: none;
color: #ff0000;
background-color: black;
}
.nav li .active a {
color: #ff0000 !important;
}
Still, when I want to change the background color - it works. Just doesn't change color of the text.
You can do:
.nav li.active a {
color: #ff0000;
}
This way you can also get rid of the !important because it is more specific than the other rules
Ok, I just worked it out one moment later. I deleted "li" from the css line and it worked. Probably because .active is the class name of that li tag.
.nav .active a {
color: #ff0000 !important;
}
Hope it will help somebody else.

css How can I make the background of a link behave like the link itself?

So clicking on the background of a link would open up the link, or hovering over the background would turn the cursor icon into a pointer icon.
EDIT: Here is my yucky code that I didn't bother to show at first because of shame.
a{
color: #815853;
text-decoration: none;
display: inline-block;
}
a:hover{
color: #e3ddce;
}
ul li {
color: #e3ddce;
display: inline-block;
list-style-type: none;
padding: 5px 15px;
}
ul li:hover {
background: #815853;
border: 1px solid black;
border-radius: 5px;
}`
You mean like this?
.clicky {
background-color: cyan;
}
<a href="https://stackoverflow.com" _target="blank">
<div class="clicky">
click here
</div>
</a>
.harshit {
background-color: yellow;
color:red;
}
<a href="https://stackoverflow.com" _target="blank">
<div class="harshit">
click me
</div>
</a>

Select whole body except a class in body

I would like to change the look of all anchor tags in the body except ones in the navbar, I tried:
a:not(.navbar) a {
color: #333;
}
a:hover:not(.navbar): {
color: #999;
}
But it doesn't work, all tags became the same.
Is this possible?
EDIT: I have some other attributes such as transitions as well, so I can't set the restore the values for the rest.
Have you tried selecting .navbar a tags and restoring their values?
a {
color: #333;
}
a:hover {
color: #999;
transition: color 2s;
}
.navbar a,
.navbar a:hover {
color: initial;
transition: none;
}
I think the code is quite self-explanatory, but I'll explain it:
Select all divs except the ones with class "navbar", and to all links inside those apply certain styles.
div:not(.navbar) a {
color: #333;
}
div:not(.navbar) a:hover {
color: #999;
}
div:not(.navbar) a {
color: red;
}
div:not(.navbar) a:hover {
color: green;
}
<div>
link
</div>
<div class="navbar">
link should NOT be red
</div>
<div>
link
</div>

why doesn't block <a> within <li> accept color set in css file?

I am trying to understand how to change color of "a" tags within "li" elements. I have the following unordered list:
<nav class="navbar navbar-default navbar-fixed-top">
...
<ul class="nav navbar-nav navbar-left">
<li>About</li>
<li>Blog</li>
<li>Contact</li>
</ul>
...
</nav>
Why does the following work:
.navbar-default .navbar-nav li a {
color: #333333;
}
.navbar-default .navbar-nav li a:hover {
color: #EC5216;
}
But not:
li a {
color: #333333;
}
li:hover a {
color: #EC5216;
}
nor:
a {
color: #333333;
}
a:hover {
color: #EC5216;
}
I have read this post, but it is still unclear. Thanks ahead of time for the answers!
There is a hierarchy on the selectors that is counted. The more selectors you put, the higher it's defined style gets in the hierarchy.
Let's say for example you use just
a {
style....
}
this a has a total weight of 5.
But if you do a
.class a {
style...
}
.class has another 5 so 5+5 = 10 and will have higher priority.
You can test this by putting !important to lower-hierarchy statements.
see here
https://www.smashingmagazine.com/2007/07/css-specificity-things-you-should-know/
That is because
.navbar-default .navbar-nav li a {
color: #333333;
}
.navbar-default .navbar-nav li a:hover {
color: #EC5216;
}
has more weight and is more specific than
li a {
color: #333333;
}
li:hover a {
color: #EC5216;
}
a {
color: #333333;
}
a:hover {
color: #EC5216;
}
Please read more on CSS specificity..
https://developer.mozilla.org/en/docs/Web/CSS/Specificity

How do I get two colors in one hyperlink?

I have a hyperlink in my website that I want to be part #A0A0A0 and part #880000 for a:link and a:visited, and I want it to change to part #FFFFFF and part #AA0000 for a:hover and a:active. But I want it to be all one link. I have tried two solutions so far, but neither worked out the way I want.
The first was:
a.menu:link { color: #a0a0a0; text-decoration: none; }
a.menu:visited { color: #a0a0a0; text-decoration: none; }
a.menu:hover { color: #ffffff; text-decoration: none; }
a.menu:active { color: #ffffff; text-decoration: none; }
<a class="menu" href="/about.html">Dubious
<span style="color: #880000;">Array</span>
.net</a>
In this solution, the color of the middle part ('Array') stays as #880000 the whole time and doesn't change to #AA0000 for :hover or :active.
The second solution was to create a <a> </a> for each part of the string (so one for 'Dubious', one for 'Array' and one for '.net') and have the css for the middle <a> </a> be
a.redMenu:link { color: #880000; text-decoration: none; }
a.redMenu:visited { color: #880000; text-decoration: none; }
a.redMenu:hover { color: #AA0000; text-decoration: none; }
a.redMenu:active { color: #AA0000; text-decoration: none; }
The colors worked fine this way; but the string was three separate links, so mousing over one link wouldn't change the color in the others.
So what I want to be able to do is to change the css in the middle of a hyperlink from a.menu to a.redMenu then back again to a.menu, but I can't work out how. Can anyone here solve my problem?
Thanks, Jacob
You can use your original HTML, just remove the inline style:
<a class="menu" href="/about.html">
Dubious<span>Array</span>.net
</a>
Then simply add these css declarations for span:
a.menu:link span, a.menu:visited span{color: #880000;}
a.menu:hover span, a.menu:active span {color: #aa0000;}
a.redMenu:hover span { color: #AA0000; text-decoration: none; }
This tells the span what color to be when it's parent link is hovered.
<html>
<head>
<style type="text/css">
p { background: #00c }
a.menu:link { color: #a0a0a0; text-decoration: none; }
a.menu:visited { color: #a0a0a0; text-decoration: none; }
a.menu:active { color: #ffffff; text-decoration: none; }
a.menu:hover span.normal { color: #800 }
a.menu:hover span.hilite { color: #880 }
</style>
</head>
<body>
<p><a class="menu" href="/about.html"><span class="normal">Dubious
<span class="hilite">Array</span> .net</span></a>
</p>
</body>
</html>