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

Categories

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

html - What am I missing? Font color in CSS

If I write the same block of code below but don't include the "body" element (which also doesn't appear to do anything) then my h1 text stays black. Why is this happening? If I understand correctly, I should be able to add the h1 portion and it should change colors right?

edit: I want to clarify that I'd like to exclude the "body" portion, and want to understand why I can't. As another example, I previously had size settings for the image in the code. When I placed these settings before the h1 portion, h1 changed colors. If h1 was after, then it stayed black again.

   <style>
    
    body{
      color: pink;
    }
    h2{
      color: blue;
    }
    
    </style>

    <h1 id="title" class="title">Katherine Johnson</h1>
    <div id="img-div">
      <img id= "image"    src="https://www.nasa.gov/sites/default/files/thumbnails/image/26646856911_ca242812ee_o_1.jpg" alt="Katherine Johnson" class="center">
      <h2 id="tribute-info"><ul> <li>Born in White Sulphur Springs, West Virginia, in 1918, her intense curiosity and brilliance with numbers vaulted her ahead several grades in school.</li> </li>By 13, she was attending the high school on the campus of historically black West Virginia State College. </li> <li>At 18, she enrolled in the college itself, where she made quick work of the school’s math curriculum and found a mentor in math professor W. W. Schieffelin Claytor, the third African American to earn a PhD in mathematics. </li> <li>She graduated with highest honors in 1937 and took a job teaching at a black public school in Virginia. </li> </ul></h2>  
      <a id="tribute-link" target="_blank" href="https://www.nasa.gov/content/katherine-johnson-biography"> Learn more about Katherine here</a>
      
    </div>
question from:https://stackoverflow.com/questions/65650503/what-am-i-missing-font-color-in-css

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

1 Reply

0 votes
by (71.8m points)

You have provided class and id to make CSS effective. Use class/id to make CSS effective instead of an anchor tags.

<style>

body{
  color: pink;
}
h2Class{
  color: blue;
}

</style>



<h1 id="title" class="h2Class">Katherine Johnson</h1>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...