Override CSS for a:link by class - html

In the existing CSS file, we have:
a:link {
text-decoration: none;
color: #0486d9;
}
a:visited {
text-decoration: none;
color: #0486d9;
}
Which is fine, but I don't want that style in all cases. For example, for this link, I want it always white and underlined:
<a id="someId" class="GridviewSort" href="...">Date</a>
I thought this would do it:
.GridviewSort a:link {
text-decoration: underline;
color: white;
}
.GridviewSort a:visited {
text-decoration: underline;
color: white;
}
But it's not. The original style remains. What am I doing wrong?
EDIT:
Thanks, stybl. For some reason the original blue is still being dominant. But the Underline is working! Here's what's happening:
EDIT 2:
Ok, further up in the same style sheet is this:
a {
color: #0486d9 !important;
}
Which is still forcing the link to be blue. I don't want to change or remove this line because of the impact it might have elsewhere in the site. Is there a way to override this one too?

.GridviewSort a:visited targets <a> tags that are children of elements with the GridviewSort class. What you want is to target <a> tags that have that class.
This should work:
a.GridviewSort:link {
text-decoration: underline;
color: white;
}
a.GridviewSort:visited {
text-decoration: underline;
color: white;
}
Note: if you intend to have the same exact style for both clicked and unclicked links, you can shorten it like so:
a.GridviewSort:link,
a.GridviewSort:visited {
text-decoration: underline;
color: white;
}

Related

How to use different colors in the same HTML link? [duplicate]

This question already has an answer here:
Remove underline from part of a link
(1 answer)
Closed 1 year ago.
I'm trying to use different colors in the same HTML link. It seems to work at first, but when I hover over the link with the mouse, the underline is drawn with only a single color.
I'm using this HTML as CSS:
body {
background: #E7CEAF;
}
a {
color: white;
background: darkred;
text-decoration: none;
}
a:hover {
color: powderblue;
text-decoration: underline;
}
.tag {
font-style: italic;
color: yellow;
}
a:hover .tag {
text-decoration: none !important;
/* doesn't work */
}
This is some text: <span class="tag">[this is a tag] </span>This is a link, the tag being part of the link
You can play with it on JSFiddle.
As you can see there, the underline is blue, even under the yellow words. How can I style the hovering links to display a yellow underline (or even no line) under the yellow part?
Your code part for a:hover .tag works fine and is rendered correctly, but there is an underline on the link on its own. So you need to remove the underline on the link and add it only to part with text.
body {
background: #E7CEAF;
}
a {
color: white;
background: darkred;
text-decoration: none;
}
a:hover {
color: powderblue;
text-decoration: none;
}
.tag {
font-style: italic;
color: yellow;
}
a:hover .tag {
text-decoration: underline;
}
a:hover .text {
text-decoration: underline;
}
This is some text: <a href="https://www.example.com">
<span class="tag">[this is a tag] </span>
<span class="text">This is a link, the tag being part of the link</span></a>

css styles not working if php file is target in <a href>

If target file is .php none of the formatting for the tag will be applied. Only if the tag is for a .html or .htm will the formatting apply. The link works either way and the .php file is loaded.
Email2
tag formatted properly from css file
Email2
no format applied
tags applied:
a {
color: #cccccc;
}
a:hover {
color: hotpink;
}
Hope I am doing this right:
Here is the fiddle page of all the html and css
you will see that the formatting is done on the .html but not on the .php
Thank you
https://jsfiddle.net/96fcapmw/
In your fiddle, your CSS ends like this:
.footer a:hover {
color: hotpink;
text-decoration: underline;
}
.footer a:visited {
color: #fff;
}
But that way, the a:visited style will always overwrite the a:hover style as soon as you have clicked that link once, just because of the order of those to rules. (the second always overwrites the first one, if it has been visited once)
To avoid that, just turn the order around:
.footer a:visited {
color: #fff;
}
.footer a:hover {
color: hotpink;
text-decoration: underline;
}
Here it's done that way in the fiddle: https://jsfiddle.net/ntfx5xws/1/

Change css style without affecting other elements

Now I have a element who change color of button to blue... That I want to do I think is very simple but I donĀ“t have enough knowledge of css.
I want to do another class without removing current class, How can I do it?
jsFiddle
Code:
<div>
<div class='btn btn-success'>
<a href='javascript:Addlog(" + id + ");' role='button'>
<i class='fa fa-pencil-square-o'></i> Complete</a>
</div></div>
CSS:
a, .a {
color: #003F8F;
}
a:hover, a:focus {
color: #23527c;
text-decoration: underline;
}
I want to add something like:
a, .a {
color: white;
}
a:hover, a:focus {
color: white;
text-decoration: none;
}
But without removing current css to not affect code that already exists
Use a CSS class then which you can dynamically add or remove from arbitrary elements.
.light {
color: white;
}
a.light:hover,
a.light:focus {
color: white;
text-decoration: none;
}
JS example, assuming your link has class="color-change-button":
document.querySelector('.color-change-button').addEventListener('click', function() {
this.classList.toggle('light');
});
https://jsfiddle.net/DTcHh/27351/

Link that looks like an image button doesn't listen to color: instruction in css

I have a page at http://www.problemio.com/problems/problem.php,
and you see on the bottom-right I have a teal image. It is really a link and in that link I can't seem to get the text color to appear white.
Here is my CSS:
.button
{
display: block;
background: #4E9CAF;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
text-color: white;
font-weight: bold;
text-decoration: none;
}
a:button.visited
{
display: block;
background: #4E9CAF;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
text-color: white;
font-weight: bold;
text-decoration: none;
}
and here is how I make the link with HTML:
<a class="button" id="follow_problem" href="#" title="...">Follow Problem</a>
Any idea what is going wrong and why the color of the link isn't white?
It appears that you're trying to override the styling of the a:link class Try:
Option 1:
Here is the class you're trying to override:
a:link {
color: #3686A7;
text-decoration: none;
}
You need to add !important to the end of your style declaration:
.button {
color: white !important;
}
Option 2:
You could further define the a:link class rules:
a:link.button {
color: white;
}
That's because a:link (line 95) is more specific than .button (line 109).
You can fix it by changing the rule to
.button,
a:link.button {
/* rules */
}
Tips:
While using !important will work, it is a silly workaround that will eventually get you in trouble, and it is actually a misuse - http://www.w3.org/TR/CSS2/cascade.html#important-rules
Use Firebug for Firefox, or Chrome's inspect element, to check the css affecting a given element.
In your .button class, use this: color: white !important;. The problem happens because the a style declaration is applied after the .button declaration, in effect cancelling the color you have set in favor of the link 's color property. Using !important ensures the color rule is applied over any other.
That's because you have another class in common_elements.css that has higher priority than .button
a:link
{
color: #3686A7;
text-decoration: none;
}
Try making your .button more prioritized by !important

change default hyperlink properties in custom tag

I've got the following.. http://jsfiddle.net/JcLx4/31/ how would I change the properties of the hyperlinked text in this example from blue and underlined to black and not underlined?
At a very basic level, like this:
a:link
{
color: black;
text-decoration: none;
}
To make it specific to links within your custom tag (incorporating display:block to make your link stretch the width of its container):
ab.s a:link
{
color: #000;
display: block;
text-decoration: none;
}
And to change the hover style:
ab.s a:hover
{
background-color: #000;
color: #fff;
}
If you want more information there is a tutorial on this page that explains the different pseudo-classes.
ab.s a{
text-decoration:none;
color: #000;
}