【问题标题】:ID selectors not working in my CSSID 选择器在我的 CSS 中不起作用
【发布时间】:2011-10-07 02:18:22
【问题描述】:

我无法弄清楚这里有什么问题。我的 CSS 样式不适用于我的某些 ID,也就是说,样式没有被应用,甚至没有被 chrome 或 FF 看到。 不工作的ID都是1_1、1_2、1_3之类的。

请注意,ID“buttons_menu”是有效的。

HTML:

    <div id="buttons_menu">
        <div class="row">
            <div id="1_3" class="menu-item"></div>
            <div id="2_3" class="menu-item"></div>
            <div id="3_3" class="menu-item"></div>
        </div>
        <div class="row">
            <div id="1_2" class="menu-item"></div>
            <div id="2_2" class="menu-item"></div>
            <div id="3_2" class="menu-item"></div>
        </div>
        <div class="row">
            <div id="1_1" class="menu-item"></div>
            <div id="2_1" class="menu-item"></div>
            <div id="3_1" class="menu-item"></div>
        </div>
    </div>

CSS:

   body{
    -webkit-tap-highlight-color:rgba(0,0,0,0);
    width: 1024px;
    height: 768px;
    background-color: white;
    margin: 0px;
    padding: 0px;
    position: relative;
    background: white url('../images/index/bg.png') no-repeat;
}
#buttons_menu{
    position:absolute;
    top:250px;
    left:66px;
    height:100%;
    width:100%;
}
.row{
    margin-bottom: 26px;
}
.menu-item{
    display: inline-block;
    border:1px solid black;
    margin-right: 5px;
    width: 209px;
    height: 122px;
}
#1_3{
    background: url('../images/index/1_3.png') no-repeat;
}
#2_3{
    background: url('../images/index/2_3.png') no-repeat;
}
#3_3{
    background: url('../images/index/3_3.png') no-repeat;
}
#1_2{
    background: url('../images/index/1_2.png') no-repeat;
}
#2_2{
    background: url('../images/index/2_2.png') no-repeat;
}
#3_2{
    background: url('../images/index/3_2.png') no-repeat;
}
#1_1{
    background: url('../images/index/1_1.png') no-repeat;
}
#2_1{
    background: url('../images/index/2_1.png') no-repeat;
}
#3_1{
    background: url('../images/index/3_1.png') no-repeat;
}

【问题讨论】:

    标签: html css css-selectors


    【解决方案1】:

    An HTML ID cannot begin with a number。改成some_prefix_1

    有关更多信息,请参阅this question - XHTML 中还有其他限制......而 HTML5 似乎采取了更宽松的路线。

    【讨论】:

    • HTML 4 can't 的 ID 以数字开头,HTML 5 can(可能,虽然规范有点模糊)。
    • @DavidThomas - 非常正确!您在我添加附加句子时发表了评论:-)
    • - @DavidThomas,一点也不 - 谢谢你的评论!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 2014-06-28
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    相关资源
    最近更新 更多