美文网首页
CSS-选择器11-first-of-type、last-of-

CSS-选择器11-first-of-type、last-of-

作者: Java小工匠 | 来源:发表于2017-06-11 14:10 被阅读0次

CSS选择器-系列文章

1、选择器说明

选择器 例子 例子描述 CSS
:first-of-type p:first-of-type 选择属于其父元素的首个 p 元素的每个 p 元素。 3
:last-of-type p:last-of-type 选择属于其父元素的最后 p 元素的每个 p 元素。 3
:only-of-type p:only-of-type 选择属于其父元素唯一的p 元素的每个 p 元素。 3
:nth-of-type(n) p:nth-of-type(2) 选择属于其父元素第二个 p 元素的每个p元素。 3
:nth-last-of-type(n) p:nth-last-of-type(2) 同上,但是从最后一个子元素开始计数。 3

2、效果演示

源代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CSS伪类选择器</title>
    <style type="text/css">
        .div{
            width: 100px;
        }
        .div:first-of-type{
            color: red;
        }
        .div:last-of-type{
            color: blue;
        }
        .div:nth-of-type(3){
            border: 1px solid red;
        }
        .div:nth-last-of-type(2){
            border: 1px solid blue;
        }
    </style>
</head>
<body>
    <p class="p">p1</div>
    <div class="div">div1</div>
    <p class="p">p2</div>
    <div class="div">div2</div>
    <p class="p">p3</div>
    <div class="div">div3</div>
    <p class="p">p4</div>
    <div class="div">div4</div>
    <p class="p">p5</div>
    <div class="div">div5</div>
</body>
</html>

运行效果:


image.png

CSS选择器-系列文章
下一节 选择器12-:empty

相关文章

  • CSS-选择器11-first-of-type、last-of-

    CSS选择器-系列文章 1、选择器说明 2、效果演示 源代码 运行效果: CSS选择器-系列文章下一节 选择器12...

  • css-选择器

    CSS选择器最主要的基础选择器。 选择器 含义通用元素选择器,匹配页面任何元素。(这也就决定了我们很少使用)...

  • CSS-选择器

    标签选择器 指用HTML标签名称作为选择器,按标签名进行分类,为页面中的某一类标签指定为同一样式。 类选择器 类选...

  • CSS-选择器

    1、元素/标签/类型选择器 以标签作为选择器 p{color:#f00;} div{ba...

  • CSS-选择器

    一、什么是选择器 选择器是指通过一定的语法规则选取对应的HTML标记,然后给对应的HTML标记设置样式。选择器分为...

  • CSS-选择器

    选择器

  • CSS-选择器

    标签选择器 标签选择器是指用HTML标签名作为选择器,可以把某一类标签全部选择出来,然后为页面中某一类标签指定统一...

  • CSS-常用选择器

    常用选择器 子代和父代选择器 伪类选择器 伪元素 属性选择器 孩子选择器 兄弟选择器 否定伪类 优先选择器 a的伪类

  • css-选择器类型

    一、元素选择器 文档元素为最基本的选择器示例: 二、id选择器 id 选择器可以为标有特定 id 的 HTML 元...

  • CSS-属性&&选择器

    CSS选择器、CSS属性 css的固定格式: 注意点: style写在head中间,type="text/css"...

网友评论

      本文标题:CSS-选择器11-first-of-type、last-of-

      本文链接:https://www.haomeiwen.com/subject/viuhqxtx.html