user3546093
user3546093

Reputation:

Why isn't an a tag styled inside a div?

Why is the word "exemple" black here

<div style="color: red"><a href="http://exemple.com">Exemple</a></div>

while it becomes red here

<div style="color: red"><p>Exemple</p></div>

and even here

<div style="color: red"><a>Exemple</a></div>

Maybe there is a problem with 'href' attribute ?

PS : I know, that I can directly style an <a> tag, but I think my question is still interesting.

Upvotes: 1

Views: 92

Answers (2)

Tomtiger11
Tomtiger11

Reputation: 53

a does not inherit it's color from its parent. You have to style it directly, either through a {color:red;} or <a style="color: red">

Upvotes: -1

Quentin
Quentin

Reputation: 943615

The browser provides a default stylesheet.

In that stylesheet, the default value for the color property on an a element is a shade of blue, not inherit. You haven't done anything to override the value of the color property for the a element.

The default value for the property on the p element is inherit, so it pulls in the colour from its parent element.

Upvotes: 2

Related Questions