I am trying to use Glyphicons for a portal idea and when the icon is hovered over the associated link also changes color.
<div class="portal">
<table>
<tr>
<td><div align="center"><a href="clientarea.php" class="glyphicons home"/></a></div></td>
<td><strong>Home</td>
</tr>
</table>
</div>
I have tried the following
.portal a:hover {
color: #BC2328;
}
.portal a:hover:before {
color: #BC2328;
}
But that only changes one at a time where as I would like both the icon and text url to change color; which either one is hovered over.
Help appreciated.
Like I said in my comment, I think the issue lies in that you set the specific color of the pseudo element. If you let the pseudo element read off of the styles of its parents, it will change colors with it.
You can see in this example how the first anchor tag has a specific color set on the pseudo element, whereas the second reads from its parent.
This pseudo element has a specific color set
This pseudo element has no specific color
.setColor { color: #f00; }
.setColor:before { color: #f00; content: '#'; }
.setColor:hover { color: #00f; }
.noSetColor { color: #0f0; }
.noSetColor:before { content: '#'; }
.noSetColor:hover { color: #f0f; }
In short, less is more.
css
.no:hover [class*="glyphicons"]:before {
color: yellow !important;}
HTML:
<td><div align="center" class="mydiv"><a href...
CSS:
.mydiv:hover a {color: #BC2328;}
you can try to select both elements by adding :hover pseudoclass to the parent div like this (not tested):
.portal:hover a, .portal:hover a:before {
color: #BC2328;
}
EDIT
Thanks to Chad's comment it occured to me that it is a bad practice. Therefore you should wrap your anchor tags in a separate wrapper or give this anchor an icon in a different way.
I would suggest doing sth like this (tables get a little messy sometimes):
HTML:
<div class="portal">
<a class="certain-icon" href="clientarea.php" title="Home">Home</a>
</div>
CSS:
a.certain-icon { padding-left: 30px; line-height: 20px; background: url(certain-icon.png) left center no-repeat; }
a.certain-icon:hover { color: #BC2328; background: url(certain-icon-active-state.png) left center no-repeat; }
Where padding-left is icon's width + some margin and line-height (or just height but the first one vertically centers your's anchor text) is icon's height
This is driving me nuts. I have tried all of the suggestions in the other questions regarding this and it's just NOT working.
I need to change the background color my navigation bar. I don't want to change the CSS in the Editor section (Wordpress). I've been trying to get it done in the Edit CSS section.
#nav {
position: relative;
left: -90px;
}
nav > ul {margin: 40}
This is what I have so far (which has been working, it's centered the nav bar which I wanted, and put a margin between the header and nav bar). Is there anything I can add to this to change the color of the background (and then I'll need to change the color of the font, too..)
Um, do you mean like this?
CSS:
#nav {
position: relative;
left: -90px;
background-color: #7777777; /*Whatever color you want goes here, but in Hexadecimal form*/
}
And, for the font color(s):
#nav {
position: relative;
left: -90px;
background-color: #7777777; /*Whatever color you want goes here, but in Hexadecimal form*/
color: #1122cc; /*The color of your font also goes here, but in hexadecimal form*/
}
See these links for more reference:
http://www.w3schools.com/cssref/pr_background-color.asp
http://www.w3schools.com/cssref/pr_text_color.asp
COLORS:
http://www.w3schools.com/cssref/css_colors.asp
http://www.w3schools.com/cssref/css_colornames.asp
For this HTML (I have duplicated each nav item to represent the "active" class added)
<nav>
<ul>
<li class="blue">Normal</li>
<li class="green">Normal</li>
<li class="red">Normal</li>
<li class="blue active">Active</li>
<li class="green active">Active</li>
<li class="red active">Active</li>
</ul>
</nav>
I would use this CSS (note the CSS classes chained together, eg: .blue.active)
Here's a way of changing the color. You can also use images or css to use gradients.
#nav {
position: relative;
left: -90px;
background-color: #336699; // change #000088 (blue) for the color your want
color: #FFFFFF; // change #FFFFFF (white) for the color you want.
}
You can use a color picker to get the color you want.
My html code is:
<div id="arrow">
<b>Filter By: </b>
All
<input type="text" size="3" style="display: none;" id="DateFilter" />
EndDate
My Requests
</div>
My css code is:
a:active {font-family: Verdana, Sans-serif;
color:#FF0000;
text-decoration:none;
background: url("Images/arrow_down.png") no-repeat;
background-position:center;
}
Here i want the arrow image to come under the active link so that it indicates that it is active..
I have tried the above code but i m not getting the desired output..
You can display the arrow with pure CSS (see below), but you'll need javascript to keep the class "alive".
Demo (click on a link)
HTML:
<b>Filter By: </b>
All
EndDate
My Requests
CSS:
a {
position:relative;
}
a:active:after, a.active:after {
background: url("Images/arrow_down.png");
width:10px; /* arrow's width */
height:10px; /* arrow's height */
margin-left:-5px; /* half of arrow's width */
position:absolute;
top:100%;
right:50%;
content:" ";
}
jQuery:
$('a').on('click',function(){
$('a').removeClass('active');
$(this).addClass('active');
});
You may have to use some script to do that. Create a separate class for active state and add that class on click.
$('a').click(function(){
$(this).addClass("active");
});
Here is the demo http://jsfiddle.net/qvQxp/1/
I tried Giona's answer and found that the negative magin for margin-left was being ignored by the browser and the arrow was still off center by half the width of the arrow image. To fix this, apply the negative margin to margin-right instead.
I have a background color on my links (on hover, rails-style). And I have an img inside an a-tag that I don't want to have a background on hover.
I tried
a:hover img{ background-color: #fff; }
but that's not doing anything. How do I exclude img-tags inside a-tags from the hover?
Thx,
MrB
edit: jsFiddle
http://jsfiddle.net/rasvf/1/
In the example: "google" has a red background on hover, as intended. But when you hover over the image, it also does. It's supposed not to have a hover background.
if i understand you correctly, i think you are trying to do something like this:
a:hover img{ visibility: hidden; }
or
a:hover img{ display: none; }
EDIT
In that case you want:
a:hover img {background-color: transparent;}
Example posted on: http://jsfiddle.net/6qwJy/
It's hard to understand your example. Say I have this piece of HTML:
<a class="foo" href="#"><img src="bar.gif"/> Click me</a>
then with these style rules
a#foo:hover { background-color: blue; }
a#foo img { background-color: white; }
the image background color will always be white, also on hover.
If however you have background images on the element that contains your link and you want that to show behind the foreground image, then you can't do this. In that case you'll have to wrap the "Click me" text of the link in a span and write in your stylesheet:
a#foo:hover span { background-color: blue; }
Is this what you intended?
Ah! I did it. Easy. I just put the not-to-have-a-background-image in a different div and then did:
.otherdiv a:hover{ background-color: transparent; }
a img {
vertical-align: bottom;
}
Ok, you won't believe me, but I had the same problem above and I resolved as follows:
I had something like this:
<img src"path/to/image.gif">
And in my CSS I had:
a:hover { text-decoration: underline; }
And, believe me, I just had to put the 'img' tag in the same line as the 'a' tag, like this:
<img src="path/to/img.gif">
And that was all!!!
I would like to show a div when someone hovers over an <a> element, but I would like to do this in CSS and not JavaScript. Do you know how this can be achieved?
You can do something like this:
div {
display: none;
}
a:hover + div {
display: block;
}
<a>Hover over me!</a>
<div>Stuff shown on hover</div>
This uses the adjacent sibling selector, and is the basis of the suckerfish dropdown menu.
HTML5 allows anchor elements to wrap almost anything, so in that case the div element can be made a child of the anchor. Otherwise the principle is the same - use the :hover pseudo-class to change the display property of another element.
.showme {
display: none;
}
.showhim:hover .showme {
display: block;
}
<div class="showhim">HOVER ME
<div class="showme">hai</div>
</div>
jsfiddle
Since this answer is popular I think a small explanation is needed. Using this method when you hover on the internal element, it wont disappear.
Because the .showme is inside .showhim it will not disappear when you move your mouse between the two lines of text (or whatever it is).
These are example of quirqs you need to take care of when implementing such behavior.
It all depends what you need this for. This method is better for a menu style scenario, while Yi Jiang's is better for tooltips.
I found using opacity is better, it allows you to add css3 transitions to make a nice finished hover effect. The transitions will just be dropped by older IE browsers, so it degrades gracefully to.
#stuff {
opacity: 0.0;
-webkit-transition: all 500ms ease-in-out;
-moz-transition: all 500ms ease-in-out;
-ms-transition: all 500ms ease-in-out;
-o-transition: all 500ms ease-in-out;
transition: all 500ms ease-in-out;
}
#hover {
width:80px;
height:20px;
background-color:green;
margin-bottom:15px;
}
#hover:hover + #stuff {
opacity: 1.0;
}
<div id="hover">Hover</div>
<div id="stuff">stuff</div>
I'm by no means an expert, but I'm incredibly proud of myself for having worked something out about this code. If you do:
div {
display: none;
}
a:hover > div {
display: block;
}
Note the >, a direct child selector.
You can contain the whole thing in an a tag, then, as long as your trigger (which can be in it's own div, or straight up in the a tag, or anything you want) is physically touching the revealed div, you can move your mouse from one to the other.
Maybe this isn't useful for a great deal, but I had to set my revealed div to overflow: auto, so sometimes it had scroll bars, which couldn't be used as soon as you move away from the div.
In fact, after finally working out how to make the revealed div, (although it is now a child of the trigger, not a sibling), sit behind the trigger, in terms of z-index, (with a little help from this page: How to get a parent element to appear above child) you don't even have to roll over the revealed div to scroll it, just stay hovering over the trigger and use your wheel, or whatever.
My revealed div covers most of the page, so this technique makes it a lot more permanent, rather than the screen flashing from one state to another with every move of the mouse. It's really intuitive actually, hence why I'm really quite proud of myself.
The only downside is that you can't put links within the whole thing, but you can use the whole thing as one big link.
This answer doesn't require that you know the what type of display (inline, etc.) the hideable element is supposed to be when being shown:
.hoverable:not(:hover) + .show-on-hover {
display: none;
}
<a class="hoverable">Hover over me!</a>
<div class="show-on-hover">I'm a block element.</div>
<hr />
<a class="hoverable">Hover over me also!</a>
<span class="show-on-hover">I'm an inline element.</span>
This uses the adjacent sibling selector and the not selector.
I would like to offer this general purpose template solution that expands on the correct solution provided by Yi Jiang's.
The additional benefits include:
support for hovering over any element type, or multiple elements;
the popup can be any element type or set of elements, including objects;
self-documenting code;
ensures the pop-up appears over the other elements;
a sound basis to follow if you are generating html code from a database.
In the html you place the following structure:
<div class="information_popup_container">
<div class="information">
<!-- The thing or things you want to hover over go here such as images, tables,
paragraphs, objects other divisions etc. -->
</div>
<div class="popup_information">
<!-- The thing or things you want to popup go here such as images, tables,
paragraphs, objects other divisions etc. -->
</div>
</div>
In the css you place the following structure:
div.information_popup_container {
position: absolute;
width:0px;
height:0px;
/* Position Information */
/* Appearance Information */
}
div.information_popup_container > div.information {
/* Position Information */
/* Appearance Information */
}
div.information_popup_container > div.popup_information {
position: fixed;
visibility: hidden;
/* Position Information */
/* Appearance Information */
}
div.information_popup_container > div.information:hover + div.popup_information {
visibility: visible;
z-index: 200;
}
A few points to note are:
Because the position of the div.popup is set to fixed (would also work with absolute) the content is not inside the normal flow of the document which allows the visible attribute to work well.
z-index is set to ensure that the div.popup appears above the other page elements.
The information_popup_container is set to a small size and thus cannot be hovered over.
This code only supports hovering over the div.information element. To support hovering over both the div.information and div.popup then see Hover Over The Popup below.
It has been tested and works as expected in Opera 12.16 Internet Explorer 10.0.9200, Firefox 18.0 and Google Chrome 28.0.15.
Hover Over The Popup
As additional information. When the popup contains information that you might want to cut and paste or contains an object that you might want to interact with then first replace:
div.information_popup_container > div.information:hover + div.popup_information {
visibility: visible;
z-index: 200;
}
with
div.information_popup_container > div.information:hover + div.popup_information
,div.information_popup_container > div.popup_information:hover {
visibility: visible;
z-index: 200;
}
And second, adjust the position of div.popup so that there is an overlap with div.information. A few pixels is sufficient to ensure that the div.popup is can receive the hover when moving the cusor off div.information.
This does not work as expected with Internet Explorer 10.0.9200 and does work as expected with Opera 12.16, Firefox 18.0 and Google Chrome 28.0.15.
See fiddle http://jsfiddle.net/F68Le/ for a complete example with a popup multilevel menu.
The + allow 'select' only first not nested element , the > select nested elements only - the better is to use ~ which allow to select arbitrary element which is child of parent hovered element. Using opacity/width and transition you can provide smooth appear
div { transition: all 1s }
.ccc, .ggg { opacity: 0; color: red}
.ccc { height: 0 }
.aaa:hover ~ .bbb .ccc { opacity: 1; height: 34px }
.aaa:hover ~ .eee .fff .ggg { opacity: 1 }
<div class="aaa">Hover me... to see<br><br> </div>
<div class='bbb'>BBBBB
<div class='ccc'>CCCCC
<div class='ddd'>DDDDD</div>
</div>
</div>
<div class='eee'>EEEEE
<div class='fff'>FFFFF
<div class='ggg'>GGGGG</div>
<div class='hhh'>HHHHH</div>
</div>
</div>
please test this code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">
div
{
display:none;
color:black
width:100px;
height:100px;
background:white;
animation:myfirst 9s;
-moz-animation:myfirst 9s; /* Firefox */
-webkit-animation:myfirst 5s; /* Safari and Chrome */
}
#keyframes myfirst
{
0% {background:blue;}
25% {background:yellow;}
50% {background:blue;}
100% {background:green;}
}
#-moz-keyframes myfirst /* Firefox */
{
0% {background:white;}
50% {background:blue;}
100% {background:green;}
}
#-webkit-keyframes myfirst /* Safari and Chrome */
{
0% {background:red;}
25% {background:yellow;}
50% {background:blue;}
100% {background:green;}
}
a:hover + div{
display:inline;
}
</style>
</head>
<body>
Hover over me!
<div>the color is changing now</div>
<div></div>
</body>
</html>
For me, if I want to interact with the hidden div without seeing it disappear each time I leave the triggering element (a in that case) I must add:
div:hover {
display: block;
}
Based on the main answer, this is an example, useful to display an information tooltip when clicking on a ? near a link:
document.onclick = function() { document.getElementById("tooltip").style.display = 'none'; };
document.getElementById("tooltip").onclick = function(e) { e.stopPropagation(); }
document.getElementById("help").onclick = function(e) { document.getElementById("tooltip").style.display = 'block';
e.stopPropagation(); };
#help { opacity: 0; margin-left: 0.1em; padding: 0.4em; }
a:hover + #help, #help:hover { opacity: 0.5; cursor: pointer; }
#tooltip { border: 1px solid black; display: none; padding: 0.75em; width: 50%; text-align: center; font-family: sans-serif; font-size:0.8em; }
Delete all obsolete informations<span id="help">?</span>
<div id="tooltip">All data older than 2 weeks will be deleted.</div>
HTML
<div>
<h4>Show content</h4>
</div>
<div>
<p>Hello World</p>
</div>
CSS
div+div {
display: none;
}
div:hover +div {
display: block;
}
CodePen :hover on div show text in another div
If you follow this method, element will appear even if you hover over the hidden element. This will be useful if you want to click on the hidden element. For an example you might want to see a delete option and then click on it.
<style>
#delete_link {
display: none;
}
a:hover + #delete_link {
display: block;
}
#delete_link:hover{
display: block;
}
</style>
</head>
<body>
<a>Hover over me!</a>
<div id="delete_link">Element show on hover</div>
</body>
From my testing using this CSS:
.expandable{
display: none;
}
.expand:hover+.expandable{
display:inline !important;
}
.expandable:hover{
display:inline !important;
}
And this HTML:
<div class="expand">expand</div>
<div class="expand">expand</div>
<div class="expandable">expandable</div>
, it resulted that it does expand using the second , but does not expand using the first one. So if there is a div between the hover target and the hidden div, then it will not work.
Don't forget. if you are trying to hover around an image, you have to put it around a container.
css:
.brand:hover + .brand-sales {
display: block;
}
.brand-sales {
display: none;
}
If you hover on this:
<span className="brand">
<img src="https://murmure.me/wp-content/uploads/2017/10/nike-square-1900x1900.jpg"
alt"some image class="product-card-place-logo"/>
</span>
This will show:
<div class="product-card-sales-container brand-sales">
<div class="product-card-">Message from the business goes here. They can talk alot or not</div>
</div>