加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 第一个孩子怎么样?

发布时间:2020-12-14 21:37:50 所属栏目:资源 来源:网络整理
导读:例如,我有如下HTML: div class='page' span2/span span2/span a1/a a6/a/div 第一个孩子怎么样? 我这样用:.page a:first-child {color:red} 但它不运行。 解决方法 使用 first-of-type 而不是 first-child .page a:first-of-type{ color:red;} The :fi
例如,我有如下HTML:
<div class='page'>
    <span>2</span>
    <span>2</span>
    <a>1</a>
    <a>6</a>
</div>

第一个孩子怎么样?

我这样用:.page a:first-child {color:red}

但它不运行。

解决方法

使用 first-of-type而不是 first-child
.page a:first-of-type{
    color:red;
}

The :first-of-type CSS pseudo-class represents the first sibling of its type in the list of children of its parent element.

摘自MDN Documentation.你可以找到更多的细节&示例here.

说明::first-child not working as expected

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读