【问题标题】:CSS - Style multiple ids in classCSS - 在类中设置多个 id
【发布时间】:2014-08-23 05:40:42
【问题描述】:

我希望这个 css 代码工作:

#inventoryGarbageSpot .id1,.id2,id3,id4{
padding:0px;
padding-top: 0px;
width:35px;}

如果我写一个 id 而不是多个 id 就可以了。

感谢您的帮助,

罗特姆

【问题讨论】:

    标签: css class styles


    【解决方案1】:

    像这样使用attribute selector

    风格是

      #inventoryGarbageSpot [class^="id"]{
        padding:0px;
        padding-top: 0px;
        width:35px;
        }
    

    应该是这样的

    [class^="id"]{
    
       // here style
    
    }
    

    【讨论】:

    • 你能用“id1,id2,id3,id4”的例子写你的代码吗
    • 我还是不明白把“.id1,​​.id2,.id3,.id4”放在哪里:(
    • 你想要像 id1、id2 到 id4 这样的静态 id 跟随 zessex 的回答。如果您想要动态手段,请按照我的回答谢谢
    • 请把代码放在你的css文件中,它会工作的别着急先试试
    【解决方案2】:

    如果我们分解您的选择器,您的目标是:

    • #inventoryGarbageSpot .id1
    • .id2
    • id3
    • id4

    首先,有 2 个不存在的元素:id3id4,它们将代表这种元素:

    <id3></id3>
    <id4></id4>
    

    其次,你需要在每节课前重复你的#inventoryGarbageSpot

    不要使用这个无效的选择器,而是使用这个:

    #inventoryGarbageSpot .id1,
    #inventoryGarbageSpot .id2,
    #inventoryGarbageSpot .id3,
    #inventoryGarbageSpot .id4 {
        padding:0px;
        padding-top: 0px;
        width:35px;
    }
    

    如果您想泛化您的选择器,您可以使用属性选择器,如 Sudharsan 所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      相关资源
      最近更新 更多