0

I want to overwrite background and font color of a link.

<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<link href="index.css" rel="stylesheet"/>
<style>
#abc{
    background:#ffffff; // doesn't work
    color:#008080;  // doesn't work
}
</style>
</head>

<body>
<?php include 'inc/menum.php';?>

menum.php

<div id="divL">
<a href='abc.php' id='abc'>ABC</a>
<a href='universe.php' id='universe'>UNIVERSE</a>
<a href='strel.php' id='strel'>STREL</a>
</div>

index.css

#divL  a{
background:#008080;     // works    
color:#ffffff;  // works    
}
2

5 Answers 5

2

You have a specificity issue.

The #divL a selector is more specific than #abc.

You could easily use #divL #abc and that would make the embedded rule more specific.

Sign up to request clarification or add additional context in comments.

Comments

1

Use background-color and :link

#abc{
    background-color :#fff; 

}
#abc:link {
    color:#008080;
}

instead. :link is the appropriate subclass here. color will only change the general color of the <div>, eg the content that is not anchor text..

Comments

1

Yeah! you have said that #divL a{....} works because it is selecting more specificity by selecting parent div if you can't override by just #abc{....} then you could place !important at last like this

#abc{
    background:#ffffff !important;
    color:#008080 !important;
}

Even if it is not working you should try by selecting more specificity div that is you have declared that #divL a is works

and if anytime if selecting even parent div doesn't work then you could use body selector like this

body #abc{
    background:#ffffff;
    color:#008080;
}

Also one hint for you if you would like to set background color then use background-color than background

1 Comment

!important is not required, just make the selector more specific. Overusing !important leads to style sheets that can be hard to maintain, especially for complex rule sets.
1

In this case You have to use !important

#abc{
    background:#ffffff !important;
    color:#008080 !important;
}

2 Comments

!important is not required, just make the selector more specific. Overusing !important leads to style sheets that can be hard to maintain, especially for complex rule sets.
+1 ...Yes, using more specific selector also method. I agree with you.
0

use !important to force the browser to give this value priority

E.g. background-color: red !important;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.