This question already has answers here:
HTML default link color
(3 answers)
Closed 7 years ago.
If I have a <div>, I can control its color like this:
<div class="good">Hello</div>
.good { color: green; }
I want to do the same thing for links, like this:
Hello
.good { color: green; }
I want the link to be green, even when mouse hover happens, like the <div>. I know I can do this:
.good:hover { color: green; }
But that means I have to remember to add that for every single class that may be applied to <a> element. Is there a simple way to disable hover color change for <a>? I'm thinking about something like:
a:hover { color: do-not-change; }
or:
a:hover { color: inherit-from-non-hover; }
Update
I forgot to mention that I did set global a and a:hover to override the browser default:
a, a:hover { color: black; text-decoration: none; }
This is because I don't know how to disable hover color. Ideally what I want is:
a { color: black; }
a:hover { color: <some way to tell it to not change>; }
.good { color: green; }
Then <a> is black, hover or not. And <a class="good"> is green, hover or not.
You can use inherit or initial property, but that will lead into black color on hover or what ever color property is applied to the immediate parent element of the anchor tag .
a:hover{
color: inherit; /* Inherits color property from its parent */
}
a:hover{
color: initial; /* Takes initial value of the property which is black in this case */
}
Several ways to do this...
Create a new class that can be used on any element where :hover might be a different color:
<div class="good nochange">Hello</div>
Hello
.nochange:hover{
color:inherit;
}
Add it to your class good:
Hello
.good:hover{
color:inherit;
}
Or apply it to all links:
Hello
a:hover{
color:inherit;
}
Related
Each of the links on my website has a unique color, which is defined within the style argument within each <a> tag. I want to be able to change the background color of each link on the page to aqua and change the text color to white on hover. However, because of the separate color per link, the text color does not change and is overwritten. How can I get around this?
Here is my code:
a {
color: black;
}
a:hover {
background-color: aqua;
color: white;
}
About<br>
How this site was made<br>
Upcoming Changes & Changelog<br>
Edit: To clarify, I want the links to remain the color they are, but I want them to change to white on hover, and change back on non-hover. The highlight color change already works.
Use CSS variables instead of inline color so you don't have to deal with !important and specificity issues:
a {
color: var(--c,black);
}
a:hover {
background-color: aqua;
color: white;
}
About<br>
How this site was made<br>
Upcoming Changes & Changelog<br>
You can use the !important property so it overrides the inline style
a {
color: black;
}
a:hover {
background-color: aqua;
color: white !important;
}
About<br>
How this site was made<br>
Upcoming Changes & Changelog<br>
Use the !important property to override all other declarations:
a {
color: black;
}
a:hover {
background-color: aqua;
color: white !important;
}
About<br>
How this site was made<br>
Upcoming Changes & Changelog<br>
This question already has answers here:
How are the points in CSS specificity calculated
(7 answers)
Understanding CSS selector priority / specificity
(4 answers)
Closed 3 years ago.
I have a link in a class like this:
<div class="brand">
amazona
</div>
And I changed link color and link:hover color like this:
a {
color: green;
text-decoration: none;
}
a:hover {
color: red;
}
It works perfectly. But when I change the link color in the div like this:
.brand a{
color:brown;
}
The link color is brown even I move the mouse over it. I expect the hover color to be red. Why does it happen? and how can I fix it?
To solve this problem first you need to understand CSS specificity (visit: https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity).
And if you are using .brand a CSS is becoming more specific, hence on a:hover also you need to add more specific CSS like .brand a:hover
a {
color: green;
text-decoration: none;
}
a:hover {
color: red;
}
.brand a{
color:brown;
text-decoration: none;
}
.brand a:hover{
color:red;
}
<div class="brand">
amazona
</div>
I am going to take a shot at answering this because I feel it can be better clarified. As mentioned above, a deeper understanding of the CSS language is needed, specifically a deeper understanding of CSS selectors, and how they work.
CSS implements the code you write with in your style-sheet according to order, what was write first is computed first, what was written last is computed last, therefore; if you write:
.some-txt{
color: red;
}
.some-txt{
color: blue;
}
.some-txt{
color: razzle-dazzle-purple;
}
then the text with class some-txt is going to be the color, 'razzle-dazzle-puple'.
This is becuase razzle-dazzle-puple was the last color in the order of assignment given. In your code you gave the color brown to a after red, canceling your previous assignment. To fix this you either be more specific with your selectors like so:
.brand a:hover {
color: red;
}
or just simply try moving things around, I tested your code and I think what you were looking for is this:
a {
color: green;
text-decoration: none;
}
a {
color: green;
text-decoration: none;
}
.brand a {
color: brown;
}
a:hover {
color: red;
}
remember when you add hover to a property, you are adding it to the property, so when you change that property, after you already assigned it a value, you are change the whole property. I hope this makes sense, some things are hard to explain, obviously the best way to understand something is by playing with it.
Because you specified every single link in a .brand div has the colour brown.
You can do
.brand a:hover {
color: red;
}
This will work :)
.brand a style is overriding the a:hover style. if you exchange the order of the two styles in your style-sheet it will work.
I have html table and layout for it (something like that, also i use haml+sass):
.zebra{
.zebra-stripe{
&.zebra1{
a{
color: red;
}
a:hover{
color: blue;
}
}
}
my htm table has class zebra, and tr has class .zebra-stripe .zebra1
but there i have link with other style (like button) and this link has own height with background, but color is setted to orange on hover,
.details-link{
width: 70px;
margin: 2px;
}
.details-link:hover{
color: orange;
}
but when my mouse is over this link it's color is not orange, but blue as setted for table.... what is wrong?
How to set link hover text color to orange (i setted it, but it is not viewing properly)....
If something is not clear write me in comments...
You problem is the specificity of the selectors you're using, .zebra .zebra-stripe.zebra1 a:hover is more specific than .details-link:hover. Try the following instead to make your selector more specific:
.zebra .zebra-stripe.zebra1 a.details-link:hover {
color: orange;
}
Try out this:
a.details-link:hover{
color: orange;
}
I got 4 divs and want to style them like this:
http://jsfiddle.net/AcvbG
HTML:
CSS:
#topleftbox {
background: red;
background-repeat: no-repeat;
width: 229px;
height: 228px;
float: left;
}
#topleftbox:hover {
background: blue;
}
#topleftbox:active {
background: green;
}
#topleftbox:visited {
background: yellow;
}
But replace the colors with background images. The :hover works, but :visited and :actived arent taking effect.
Anyone knows the solution? I got limited knowledge in javascript so i hope there is a way to work around this.
Your :visited and :actived pseudo class wont be visible within jsFiddle since the href="http://test". So, you need to visit the page test to see :visited in action .. AND you need to be on test page to see :active in action.
Here i made a fiddle for you
You can see where .css differs
.topleftbox:hover {
background: blue;
}
.topleftbox:visited {
background: yellow;
}
.topleftbox:visited:hover {
background: pink;
}
.topleftbox:active {
background: green;
}
Also, you should give a check to the ORDER in witch you define your styling.
a:link { color: red } /* unvisited links */
a:visited { color: > blue } /* visited links */
a:hover { color: yellow } /* user hovers */
a:active { color: lime } /* active links */
Note that the A:hover must be placed after the A:link and A:visited
rules, since otherwise the cascading rules will hide the 'color'
property of the A:hover rule. Similarly, because A:active is placed
after A:hover, the active color (lime) will apply when the user both
activates and hovers over the A element.
An example of combining dynamic pseudo-classes:
a:focus { background: yellow } a:focus:hover { background: white }
The last selector matches A elements that are in pseudo-class :focus
and in pseudo-class :hover.
In modern browsers, CSS can handle what you want without the use of javascript.
http://jsfiddle.net/CWkdY/10/
One thing to notice is that your identifier could benefit from discerning that your ID is a link by adding 'a' in front of your id declaration. Also your initial definition would benefit from 'display:block'. Like this:
a#topleftbox {
background: url('http://d241yswl6yg9sc.cloudfront.net/linen-texture2/top-new.jpg');
width: 229px;
height: 228px;
float: left;
display:block;
}
If you notice your images are initially not showing, try caching all the images you need to use with this little trick. Where you have a div with all the images, off the the side, but hidden.
http://perishablepress.com/css-image-caching/
I am using a bit of HTML in my IPhone application. I don't have much idea about HTML.
When we touch any hyperlink(ahref in HTML) there is a blue selection color that appears in "li" which contains ahref. How can we disable it?
You can override the behaviour by specifying your custom color for links via css:
a { color:green; }
Or based on their status eg active, clicked, etc:
a:active { color:green; }
a:visited { color:red; }
a:hover { color:orange; }
I'm not 100% sure, but if the text is truly being selected, and you're seeing a blue color, then the fix would be to apply a style like this:
li::selection {
background-color: transparent;
}
li::-webkit-selection {
background-color: transparent;
}
li::-moz-selection {
background-color: transparent;
}
That's only if it truly is a selection that's occuring. Mind you, only the ::selection and maybe the :-webkit-selection could possibly apply to an iPhone. ::-moz-selection would be for a Firefox browser.