【问题标题】:CSS Errors/Hacks and W3C ValidationCSS 错误/黑客和 W3C 验证
【发布时间】:2012-11-30 00:03:06
【问题描述】:

我正在查看的样式表中有以下几行(单独的):

.Ex1.Ex2 {
color:#333;
font-family:Verdana,Arial,sans-serif;
font-size:9pt;
font-weight:bold;
margin:24px 0 5px;
border-bottom:1px solid #333
}

{
background-color:#ffe;
border:1px solid #aaa;
color:#000;
font-family:Verdana,Arial,sans-serif;
font-size:9pt;
height:auto;
margin-top:5px
}

.box_title_container {
height:29px;
width:225px;
margin:0 auto;
background:url(../best_images/boxts.gif);
repeat-x
}

当通过 W3C 验证器时,两者都返回解析错误。由于创建样式表的人在 CSS 方面比我有更多的经验,我可能认为这是两种用于跨浏览兼容性的 hack,但我无法谷歌(现在它是一个动词,对吗?)任何与此相关的东西。

至于第一行,它有两个封闭的属性集,第二行有一个独立的 repeat-x 值(并且这个“错误”在接下来的 5 或 6 行中重复)。

谁能告诉我这些是出于某种目的还是纯粹的错误?

提前致谢!

【问题讨论】:

    标签: css w3c-validation


    【解决方案1】:

    在您的第一个 CSS 块中,您必须为第二个 {}

    指明 ID、类或 HTML 元素
    .Ex1.Ex2 {
    color:#333;
    font-family:Verdana,Arial,sans-serif;
    font-size:9pt;
    font-weight:bold;
    margin:24px 0 5px;
    border-bottom:1px solid #333 /* missing ;*/
    }
    
    #IDneeded .CLASSneeed {
    background-color:#ffe;
    border:1px solid #aaa;
    color:#000;
    font-family:Verdana,Arial,sans-serif;
    font-size:9pt;
    height:auto;
    margin-top:5px /* missing ;*/
    }
    

    对于第二个,“repeat-x”是“background”的值而不是 CSS 属性,只需移动 ;

    .box_title_container {
    height:29px;
    width:225px;
    margin:0 auto;
    background:url(../best_images/boxts.gif) repeat-x;
    }
    

    【讨论】:

    • 你不见了;在某些行中。
    • 谢谢!至于 ID,由于我不熟悉网站或 .css 文件,我想我会暂时保留它!
    • @Vucko:最后一个; 是可选的,不是吗?
    • 是的,最后一个“;”是可选的,它是分隔符而不是行尾要求。用“;”保存所有内容最后还是在视觉上更好(虽然)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多