举报投诉联系我们 手机版 热门标签 名动网
您的位置:名动网 > css选择器first-child CSS :first-line 选择器

css选择器first-child CSS :first-line 选择器

2023-06-01 02:20 CSS参考手册

css选择器first-child CSS :first-line 选择器

css选择器first-child

CSS选择器first-child是CSS中的一种伪类选择器,它可以用来选择文档中的第一个子元素。它可以用来设置特定的样式,从而使文档中的第一个子元素看起来不同于其他子元素。


ul li:first-child { 
    color: red; 
} 

first-child选择器可以用于所有HTML元素,但是它最常用于列表(ul、ol)和表格(table)。例如,可以使用first-child选择器来设置列表中的首项或表格中的首列不同于其他项或列。

 
 
table td:first-child { 
    background-color: #ccc; 
} 

此外,还可以使用first-child选择器来设置文章或新闻内容中的首行不同于其余内容。例如:

      article p:first-child {   font-weight: bold;   } 

总之,CSS first-child伪对象选择器是一个很强大而又很方便的工具,能够帮助我们快速地将特定样式应用到文档中的特定位置上。

CSS :first-line 选择器

CSS 选择器参考手册

实例

选择每个 <p> 元素的首行,并为其设置样式:

p:first-line
{ 
background-color:yellow;
}

亲自试一试

浏览器支持

IE Firefox Chrome Safari Opera
         

所有主流浏览器都支持 :first-line 选择器。

定义和用法

:first-line 选择器用于选取指定选择器的首行。

注释:以下属性可与 :first-line 使用:

  • 字体属性
  • 颜色属性
  • 背景属性
  • word-spacing
  • letter-spacing
  • text-decoration
  • vertical-align
  • text-transform
  • line-height
  • clear

相关页面

CSS 教程:CSS 伪元素

CSS 选择器参考手册

阅读全文
以上是名动网为你收集整理的css选择器first-child CSS :first-line 选择器全部内容。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。
相关文章
© 2024 名动网 mdwl.vip 版权所有 联系我们