<p class="butonat">
<span class="color1">Learn More </span>
I tried the following css but didn't work:
CSS (added from comment post by OP):
.butonat a.color1 {
font-size:16px;
font-family:'Source Sans Pro', FontAwesome, sans-serif;
font-weight:normal;
text-decoration:none;
text-align:center;
color:#fff;
}
There is a lot of different ways accessing your link via DOM.
Here is couple of code snippets, how you can do it.
.color1 {
color: red;
}
a span.color1 {
font-size: 30px;
}
<p class="butonat">
<span class="color1">Learn More </span>
Your CSS:
.butonat > a {
color:green;
text-decoration:none;
}
.butonat > a:hover {
color:red;
text-decoration:underline;
}
<p class="butonat">
<span class="color1">Learn More </span>
</p>
Use the above way to add the CSS on anchor tag. This way is used to apply the same CSS on a block of class.
You can apply more properties on it also.
UPDATE:
As post the CSS in question:
You need to give the space between a and class name:
.butonat a .color1 {
^^ here need space
Reason: you have not given the space to it is considering that class name is in anchor tag. After giving the space it will consider that class name is in the adjacent tag. so you need to give the space.
EDIT:
After you sent your css, i can see a missing SPACE in your selector:
.buttonat a.color1 this would mean that your a-tag has the class color1
change to
.buttonat a .color1 this will select the children witch class color1 in your a tag
Related
Please may someone explain why the text 'impact on market' is green as opposed to yellow?
I was expecting this to be yellow
HTML
<div>
<h4> International news </h4>
<article>
<h4 class= "headline"> news develop</h4>
<aside>
<h4> impact on market </h4>
</aside>
</article>
</div>
CSS
h4 {
color:blue;
}
.headline {
color:red;
}
article {
color:black;
font-style:normal;
}
aside h4 {
font-style: italic !important;
color yellow;
}
article h4 {
font-style:normal;
color: green;
}
It is because article h4 comes after aside h4 and their degree of specificity are equal. CSS files are processed from top to bottom and if another style comes along with an equal or greater specificity, then that will override the previous style.
You can use this:
side > h4 {
font-style: italic !important;
color yellow;
}
article > h4 {
font-style:normal;
color: green;
}
Where > means only affect direct descendants. This is typically better to use than !important, since !important is considered the very last resort.
Further reading on CSS specificity:
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
http://css-tricks.com/specifics-on-css-specificity/
Further reading on !important:
http://css-tricks.com/when-using-important-is-the-right-choice/
The order in which you put them. The last one is the one written last, so therefore more important.
Try:
article aside h4
{
font-style: italic !important;
color: yellow;
}
Specify the structure more.
Alternative, create a class.
<h4 class="level3"> impact on market </h4>
Then add
.level3
{
color: yellow;
}
It is all about CSS weights, here
article h4
is overriding
aside h4
you can change order or edit the
aside h4
for
article aside h4
and it will work. Both will work, change order or edit the selector.
In the below example link 2 comes out white and not black as expected how can I style the color of link two without wrapping it in a container tag?
.text a{
color:#FFF;
}
.black{
color:#000;
}
<div class="text">
Link 1
Link 2
</div>
Your second selector needs to be more specific than the first one to override it:
.text a {
color:#FFF;
}
.text a.black {
color:#000;
}
<div class="text">
Link 1
Link 2
</div>
It comes out white because the previous selector has higher specificity. One solution in this:
.black{
color:#000 !important;
}
This can cause complex problems if you use it too much, however. Generally the best solution is to try and avoid too many selectors. Have one selector that sets a default style for links, then only use classes to change specific links. For example:
a {
color: #fff;
}
.black {
color: #000;
}
It turns out white because the first selector is much more specific, namely: get a link in an element that has a class "text", whereas the last is merely get any element with the class "black".
You can solve this in two ways:
.text a.black {
color:#000;
}
OR
.black{
color:#000 !important;
}
In which 'important' overwrites other rules that are give to elements with the class "black".
here is working solution you just apply the style to black with id rather than class:
.text a{
color:#FFF;
}
#black{
color:#000;
}
<div class="text">
Link 1
Link 2
</div>
As others have mentioned, it comes out white because your previous selector for "a" tags is more specific than your "black" class.
There are two options here:
Be more specific:
.text a{
color:#FFF;
}
.text a.black {
color:#000;
}
<div class="text">
Link 1
Link 2
</div>
Or, you could us the "!important" rule:
.text a{
color:#FFF;
}
.black{
color:#000!important;
}
<div class="text">
Link 1
Link 2
</div>
I would strongly advise the first approach, but in some situations, "!important" can be a quick fix until you figure out where the real problem lies. Don't abuse the "!important" rule because it'll mess you up for the future - trust me on that!
Hope this answers your question. Have a good day.
Michael.
I have this CSS:
a {
color:#19558D;
padding:3px 5px;
text-decoration:none;
}
a:hover {
background-color:#D1E1EA;
color:#19558D;
text-decoration:none;
}
It applies to all links, but what if I don't want it to apply to a specific link on the page? What can I do?
There are two ways you can do this.
First way is to use the :not() selector and give your link that you don't want the styles applied to class:
a:not(.unstyled):hover {
background-color:#D1E1EA;
color:#19558D;
text-decoration:none;
}
However, the :not() selector is not supported in IE8 or less, so the second option is to give your unstyled links a class, and override those properties for that link with that class:
a.unstyled:hover {
background-color:none;
color:#000
text-decoration:none;
}
You can apply your own class or inline style to the link in question.
for example:
<a href="#" class="MyNewClass" />
or
<a href="#" style="color:red;" />
I have a link inside a DIV. How can I change the color of this link inside this div. This code does not seem to work
<style type="text/css">
.someDiv
{
font-size:14px;
color:#c62e16;
}
</style>
<div id="someDiv">
SOne Text
</div>
Thanks.
ids are accessed by a pound sign (#), and classes are accessed by a period (.)
<style type="text/css">
#someDiv a
{
font-size:14px;
color:#c62e16;
}
</style>
<div id="someDiv">
SOne Text
</div>
use
.someDiv a {
font-size:14px;
color:#c62e16;
}
You are using the wrong selector. You have an id="someLink", and the CSS is looking for the class="someLink". Try with #someLink, it'll work.
div#someDiv a{
color: #hexcode;
}
That will work too, you use the selector to select ALL the elements of the type "a" in a div with the id="someDiv".
While you're using the wrong selector for someDiv you will usually need to set a colours separately:
#someDiv, #someDiv a {
color: red;
}
Is there a reason my below CSS only half works?
div.share
{
position:relative;
top: -4px;
left: 25px;
font-family:Tahoma;
background-color:#000000;
font-size:11px;
font-weight:bold;
}
/* share link css */
a.share:active
{
color: #000000;
}
a.share:hover
{
color: #FFFFFF;
background-color:#000000;
text-decoration: none;
}
The div.share CSS is all working but the CSS for the active and hover is not
CSS is valid, but make sure the link does have the "share" class, if its in the DIV, change the css to:
div.share a:active
{
color: #000000;
}
div.share a:hover
{
color: #FFFFFF;
background-color:#000000;
text-decoration: none;
}
adding your html would make this easier.
I can only guess that you have a <div> with class='share' and no <a> tag with the same.
e.g., does your html look like:
<div class='share'>
<a class='share' href='http://yoursite.com'>Your site</a>
</div>
or
<div class='share'>
</div>
...
<a class='share' href='http://yoursite.com'>Your site</a>
If it's the first, then
div.share a:hover {
...
}
would make more sense.
If it's the second, then the selector looks fine... though it might be better to choose different, but appropriate class names.
Use div.share a:active and div.share a:hover.
The way you have it right now it is looking for an <a> tag with a share class applied directly. However the share class is on the outer div.
Can you show us an HTML snippet using this CSS? Is it really the <a> tag that has the share class or is it nested inside the <div class="share">?