CSS选择器



css规则

CSS高级语法

CSS派生选择器

id选择器

为标有特定 id 的 HTML 元素指定特定的样式,id 选择器以 “#”来定义。
注意:id属性只能在每个HTML文档中出现一次。

    #red {
        color: red;
    }
    
    #green {
        color: green;
    }

    #sidebar h2 {
        font-size: 1em;
        font-weight: normal;
        font-style: italic;
        margin: 0;
        line-height: 1.5;
        text-align: right;
    }

类选择器

类选择器以一个点号显示,由于扩展性较id选择器好,在实际编码中应用比较多。
注意:类名的第一个字符不能使用数字!它无法在 Mozilla 或 Firefox 中起作用。

    .center {
        text-align: center
    }

    .fancy td {
        color: #f60;
        background: #666;
    }

属性选择器

可以为拥有指定属性的 HTML 元素设置样式,而不仅限于 class 和 id 属性。

    input[type="text"] {
        width: 150px;
        display: block;
        margin-bottom: 10px;
        background-color: yellow;
        font-family: Verdana, Arial;
    }

创建CSS