嵌套类选择器 [英] Nested classes selectors

查看:73
本文介绍了嵌套类选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的HTML中有类似的内容

If I have something like this in my HTML

    <div id="top">
        <div class="txt">
            <span class="welcome">Welcome on my website</span>
            <span class="links"><a href="Home">Home</a></span>
        </div>
    </div>

如何在CSS中选择欢迎类。

How I can select the welcome class in my CSS.

我尝试了#top.txt.welcome,但是没有用。
我也尝试了#top.txt span.welcome。

I've tried #top.txt.welcome but doesn't work. I've also tried #top.txt span.welcome.

推荐答案

#top .txt 不是#top.txt
,后者表示匹配的元素具有ID和类,而前者表示匹配的元素具有类,并且其祖先元素之一具有ID

#top .txt is not #top.txt the latter means that the matched element has the id AND the class, while the former means that the matched element has the class, and one of its ancestors element has the id

这篇关于嵌套类选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆