html - 我一直在用两个 id 进行测试,第二个 id 没有做任何事情

标签 html css

 body {
      background-color:olive;
    }
    #container{
      background-color:;
      display:flex;
    }

    #container > a {
      
      background-color:chocolate;
      margin:5px;
      padding:7px;
      border-radius:10px;
    }
    

    #item-2 {

    }
    #item-4{
      margin-left:auto;
    }

    #bonus {

      background-color:red;
    }
<body>
<nav>
  <div id="container">
    <a id="item-1 bonus" href="#">Information</a>
    <a id="item-2 bonus" href="#">Contacts</a>
    <a id="item-3 bonus" href="#">Media</a>
    <a id="item-4" href="#">Logout</a>
</div>
</nav>
</body>

你好,谁能告诉我为什么“bonus”类不应用 background-color:red ?有没有规定不能放两个 id 什么的?一些澄清会非常有用。谢谢。

最佳答案

What are valid values for the id attribute in HTML?

阅读有关 HTML 属性 id 的内容。

您可以改为使用 class 属性在单个元素上使用多个类名。 id 不能这样使用。

关于html - 我一直在用两个 id 进行测试,第二个 id 没有做任何事情,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51395045/

相关文章:

html - 关于HTML5和CSS3,有哪些好的网站?

javascript - Chrome 开发工具,谁在设置高度/宽度?

javascript - 将数组中的宽度值附加到 td

css - 使用 Typescript 在我的 SASS 代码中注入(inject)背景 url ("MyImageHere.png"

JQuery 表格突出显示使用条件

html - css BEM概念

javascript - HTML5 - 如何绘制完成的 Canvas /图像

html - CSS 设置图形不可点击

css - 如何模糊 div CSS 的一部分

html - 使用类将样式应用于 div 中的元素