简体   繁体   English

CSS 背景颜色和颜色标签不起作用

[英]CSS background-color and color tags not working

I am working on some homework for my HTML class and I believe I am doing what the directions ask but it keeps marking it as wrong.我正在为我的 HTML class 做一些功课,我相信我正在按照指示做,但它一直将其标记为错误。 I tried reaching out to the professor and she told me to go read the book but I am doing it exactly as the book says and its wrong.我试着联系教授,她告诉我 go 阅读这本书,但我完全按照书上所说的去做,而且是错误的。 Maybe someone here can spot the issue.也许这里有人可以发现问题。

questions: 1: Add a blank line after the CSS reset style rule, add a comment with the text, Style rule for body and image, and then create new style rules for the body and img selectors.问题: 1:在CSS重置样式规则后添加一个空行,添加一个带有文本的注释,为body和image添加样式规则,然后为body和img选择器创建新的样式规则。

Create a style rule for the body selector that sets a background color value of #e3eaf8.为设置背景颜色值#e3eaf8 的正文选择器创建样式规则。 Create a style rule for an img selector that sets a max-width to 100% and displays the images as a block.为 img 选择器创建一个样式规则,将最大宽度设置为 100% 并将图像显示为块。

2: Add a blank line after the img style rule, add a comment with the text Style rule for header content, and then create a new style rule for the header h1 descendant selector that aligns text center; 2:在img样式规则后添加一个空行,为header内容添加一个带有文本样式规则的注释,然后为对齐文本中心的header h1后代选择器创建一个新的样式规则; sets a font size value of 3em;设置字体大小值为 3em; sets a font family value of Georgia, Times, serif;设置Georgia、Times、serif的字体系列值; sets a padding value of 3%;将填充值设置为 3%; and sets a color value of #101a2d.并将颜色值设置为#101a2d。

3: Add a blank line after the header h1 style rule, add a comment with the text Style rules for navigation area, and then create the following style rules for the nav, nav ul, nav li, and nav li a selectors. 3:在 header h1 样式规则后添加一个空行,添加一个带有导航区域样式规则文本的注释,然后为 nav、nav ul、nav li 和 nav li a 选择器创建以下样式规则。

Create a style rule for the nav selector that sets the background color to #1d396d.为导航选择器创建一个样式规则,将背景颜色设置为#1d396d。 Create a style rule for nav ul that sets the list style type to none, sets the margin to 0, and aligns text center.为 nav ul 创建一个样式规则,将列表样式类型设置为 none,将边距设置为 0,并对齐文本中心。 Create a style rule for nav li that sets the display to an inline-block, sets a font size of 1.5em, sets a font family value of Verdana, Arial, sans-serif, and a font weight value of bold.为 nav li 创建一个样式规则,将显示设置为内联块,将字体大小设置为 1.5em,将字体系列值设置为 Verdana、Arial、sans-serif,并将字体粗细值设置为粗体。 Create a style rule for nav li a that sets the display to a block, sets a font color value of #e3eaf8, sets top and bottom padding values of 0.5em and left and right padding values of 2em, and removes the text decoration.为 nav li a 创建一个样式规则,将显示设置为块,设置字体颜色值 #e3eaf8,设置顶部和底部填充值 0.5em 和左右填充值 2em,并删除文本装饰。

Those are the questions and I have tried to change my code a bunch of different ways and I can not seem to get it right这些是问题,我试图以多种不同的方式更改我的代码,但我似乎无法正确

Code:代码:

<DOCTYPE html>
<!--    
    Student Name: Nicholas Prawl
    File Name: styles.css
    Date: 02/13/2021
-->

<!-- 
    CSS Reset
    margin: 0;
    padding: 0;
    border: 0;
-->

<!--
    Style rule for body and image

    body {
      background-color: #e3eaf8;
    }
    img {
      max-width: 100%;
      display: block;
    }
-->

<!--

    Style rule for header content
     header h1 {
      text-align: center;
      font-size: 3em; 
      font-family: Georgia, Times, serif; 
      padding: 3%;
     color: #101a2d;
    }

-->

<!--
    Style rules for navigation area
    nav{
      background-color: #1d396d;
    }
    nav ul{
      list-style-type: none;
      margin: 0;
      text-align: center;
    }
    nav li{
      display: inline-block;
      font-size: 1.5em;
      font-family: Verdana, Arial, sans-serif;
      font-weight: bold;
    }
    nav li a{
      display: block;
      color: #e3eaf8;
      padding-top: 0.5em;
      padding-bottom: 0.5em;
      padding-left: 2em;
      padding-right: 2em;
      text-decoration: none;
  
    }
-->

Many things are wrong with your code.您的代码有很多问题。

First, you're adding CSS code inside what I presume to be HTML without using the style tags.首先,您要在我认为是 HTML 的代码中添加 CSS 代码,而不使用样式标签。 Please refer to this article to learn how to properly embed CSS code in HTML:请参考本文了解如何在 HTML 中正确嵌入 CSS 代码:

https://www.w3schools.com/css/css_howto.asp https://www.w3schools.com/css/css_howto.asp

Also, you're not adding the comments correctly.此外,您没有正确添加评论。 See how to add comments in CSS code here: https://developer.mozilla.org/en-US/docs/Web/CSS/Comments在此处查看如何在 CSS 代码中添加注释: https://developer.mozilla.org/en-US/docs/Web/CSS/Comments

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM