【问题标题】:Second <div> tag failing to show up with color第二个 <div> 标签未能以颜色显示
【发布时间】:2022-02-12 21:22:48
【问题描述】:

我正在尝试创建一个带有 2 个 div 标签的动画,但孩子没有出现在父级中。如何让孩子显示背景颜色?

<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Rotate</title>
  </head>
  <body>
    <style>
      .parent {
        width: 400px;
        height: 400px;
        background-color: hsla(200,100%,20%);
      };

      .child {
        width: 50%;
        height: 50%;
        background-color: red;
        z-index: 2;
      };
    </style>
    <div class = "parent">
      <div class = "child"></div>
    </div>
  </body>
</html>

【问题讨论】:

    标签: html css


    【解决方案1】:

    罪魁祸首是在.parent css 类声明之后使用分号。该分号会导致后续声明(在这种情况下为.child)被忽略:

    <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width">
        <title>Rotate</title>
      </head>
      <body>
        <style>
          .parent {
            width: 400px;
            height: 400px;
            background-color: hsla(200,100%,20%);
          }     /* <------ Removed semicolon */
    
          .child {
            width: 50%;
            height: 50%;
            background-color: red;
          }
        </style>
        <div class = "parent">
          <div class = "child"></div>
        </div>
      </body>
    </html>

    我还从.child 中删除了z-index: 2;,因为在本示例中不需要它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      相关资源
      最近更新 更多