CSS 基础语法

注:CSS对大小写不敏感,但是如果涉及到与HTML文档一起工作的时候,class和id名称对大小写是敏感的

一、color

    color:#ff0000; 

    color:#f00;    //缩写

    color:rgb(255,0,0);

    color:rgb(100%,0%,0%);    //0%的百分号不能省略

二、派生选择器

    比方说,你希望列表中的 strong 元素变为斜体字,而不是通常的粗体字,可以这样定义一个派生选择器:

    li strong {    font-style: italic;   font-weight: normal;   }

    请注意标记为 <strong> 的蓝色代码的上下文关系:

    <p><strong>我是粗体字,不是斜体字,因为我不在列表当中,所以这个规则对我不起作用</strong></p>

    <ol>     

    <li><strong>我是斜体字。这是因为 strong 元素位于 li 元素内。</strong></li>     

    <li>我是正常的字体。</li>

    </ol>

    在上面的例子中,只有 li 元素中的 strong 元素的样式为斜体字,无需为 strong 元素定义特别的 class 或 id,代码更加简洁。

 

 

原文地址:https://www.cnblogs.com/alsofly/p/4505506.html