Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

html - Color of link within H1 tag doesn't change why?

I'm trying to change the color of a link within the h1 tag. Html code as follows:

    <h1 class="redheadline">
    <a href="">Link text color here..</a> 
    </h1>

The css code I'm trying to use is:

h1.redheadline {font-size: 1.75rem; color:red;}

The font size changes but the color of the link's text doesn't change. Where in the css code I have to add color? Thanks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. h1.headline and <h1 class="redheadline"> they are not the same class name.
  2. Since its <a> element has a default color, it does not accept a color from its parent.

Chrome defaults:

enter image description here

To do this is to define the correct classes to override the default attributes of the element.

Returning to your question, we should define as h1.redheadline a { ... }.

You can run the code snippet.

h1.redheadline {
  font-size: 1.75rem;
}

h1.redheadline a {
  color: red;
}
<h1 class="redheadline">
  <a href="">Link text color here..</a>
</h1>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...