Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

css first

作者:蛋蛋的憂傷   发布日期:2026-01-30   浏览:98

/* 这是一个简单的 CSS 示例,用于选择 HTML 文档中的第一个元素并为其应用样式 */

/* 选择页面中第一个出现的 <p> 元素 */
p:first-of-type {
    color: blue;
    font-weight: bold;
}

/* 选择作为其父元素的第一个子元素的 <li> 元素 */
li:first-child {
    background-color: yellow;
}

/* 选择页面中第一个出现的 <h1> 元素 */
h1:first-of-type {
    text-decoration: underline;
}

/* 选择作为其父元素的第一个子元素的任何元素 */
*:first-child {
    margin-top: 0;
}

解释说明:

  • p:first-of-type:选择页面中第一个出现的 <p> 元素,并将其文本颜色设置为蓝色,字体加粗。
  • li:first-child:选择作为其父元素的第一个子元素的 <li> 元素,并将其背景颜色设置为黄色。
  • h1:first-of-type:选择页面中第一个出现的 <h1> 元素,并为其添加下划线。
  • *:first-child:选择作为其父元素的第一个子元素的任何元素,并将其顶部外边距设置为 0。

上一篇:css垂直水平居中

下一篇:css样式穿透

大家都在看

css好看的字体

css 红色

css 瀑布流布局grid

换行 css

css文字超长省略号

css背景图铺满

css 渐变字体

css背景图片等比例缩放

css文字删除线

css 文本下划线

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站