58t.net 58t.net

欢迎光临
我们一直在努力
顶部
域名
云服务器48/月

“不同类型的 CSS 选择器”-css教程-

css 中选择器的类型:

image description

类别选择器:

代码:

<body>
    <p class="heighlight">class of "heighlight".</p>
    <p>does not have any specific class.</p>
    <p class="heighlight">a class of "heighlight".</p>
</body>
登录后复制
<style>
.heighlight {
    color: red;
    font-weight: bold;
}
</style>
登录后复制

id选择器

代码:

<body>
    <h1 id="main-heading">this h1 has an id</h1>
    <p>this paragraph does not have an id</p>
    <p id="intro-paragraph">this paragraph has an id</p>
</body>
登录后复制
<style>
#main-heading {
    color: blue;
    font-size: 24px;

}

#intro-paragraph {
    background-color: yellow;
    padding: 10px;

}
</style>

登录后复制

元素选择器:

<body>
    <h1>welcome to my website</h1>
    <p>this is a paragraph</p>
    <p>this is another paragraph</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p>
    <a href="https:///www.google.com">visit example website</a>
</body>
登录后复制
<style>
    h1 {
        color: blue;
    }
    p {
      font-size: 16px;

    }
    a {
        text-decoration: none;
        color: red;
    }
</style>
登录后复制

通用选择器

代码:

<body>
    <h1>welcome to my website</h1>
    <p>this is a paragraph</p>
    <div>
        <h2>about us</h2>
        <p>this is another paragraph</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p>
    </div>
</body>
登录后复制
<style>
*{
    margin: 0;
    padding: 0;
    border: 1 px solid;
}
</style>
登录后复制

分组选择器:

代码:

<body>
    <h1>welcome to my website</h1>
    <p>this is a paragraph.</p>
    <a href="#">click me</a>
    <button>submit</button>
</body>
登录后复制
<style>
    h1,p {
        color: blue;
    }
    a,button {
        background-color: yellow;
        padding: 10px;
    }
</style>
登录后复制

属性选择器

代码:

<form>
    <label for="name">name:</label>
    <input type="text" id="name" required />
    <input type="submit" value="submit" />
</form>
登录后复制
<style>
    input[type="submit"] {
        background-color: #4caf50;
        color: white;
    }
    input[required] {
        border: 1px solid red;
    }
</style>
登录后复制

以上就是“不同类型的 CSS 选择器”的详细内容,更多请关注php中文网其它相关文章!

【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。
发布内容
-六神源码网 网站出售带数据-六神源码网 网站出售带数据-六神源码网 网站出售带数据-六神源码网