CSS3新增属性

26 篇文章 1 订阅

「1. CSS3属性选择器」

图片

  button {
    cursor: pointer;
  }
  button[disabled] {
    cursor: default;
  }
  input[type=search] {
    color: skyblue;
  }

  span[class^=black] {
    color: lightgreen;
  }

  span[class$=black] {
    color: lightsalmon;
  }

  span[class*=black] {
    color: lightseagreen;
  }

「2. 结构伪类选择器」

图片

ul li:first-child {
  background-color: lightseagreen;
}

ul li:last-child {
  background-color: lightcoral;
}

ul li:nth-child(3) {
  background-color: aqua;
}
  • nth-child(n)参数n详解

    • 注意:本质上就是选中第几个子元素

    • n 可以是数字、关键字、公式

    • n 如果是数字,就是选中第几个

    • 常见的关键字有 even 偶数、odd 奇数

    • 常见的公式如下(如果 n 是公式,则从 0 开始计算)

    • 但是第 0 个元素或者超出了元素的个数会被忽略

图片

<style>
  /* 偶数 */
  ul li:nth-child(even) {
    background-color: aquamarine;
  }

  /* 奇数 */
  ul li:nth-child(odd) {
    background-color: blueviolet;
  }

  /*n 是公式,从 0 开始计算 */
  ul li:nth-child(n) {
    background-color: lightcoral;
  }

  /* 偶数 */
  ul li:nth-child(2n) {
    background-color: lightskyblue;
  }

  /* 奇数 */
  ul li:nth-child(2n + 1) {
    background-color: lightsalmon;
  }

  /* 选择第 0 5 10 15, 应该怎么选 */
  ul li:nth-child(5n) {
    background-color: orangered;
  }

  /* n + 5 就是从第5个开始往后选择 */
  ul li:nth-child(n + 5) {
    background-color: peru;
  }

  /* -n + 5 前五个 */
  ul li:nth-child(-n + 5) {
    background-color: tan;
  }
</style>
  • nth-child与nth-of-type区别

    • nth-child  选择父元素里面的第几个子元素,不管是第几个类型

    • nth-of-type  选择指定类型的元素

<style>
  div :nth-child(1) {
    background-color: lightblue;
  }

  div :nth-child(2) {
    background-color: lightpink;
  }

  div span:nth-of-type(2) {
    background-color: lightseagreen;
  }

  div span:nth-of-type(3) {
    background-color: #fff;
  }
</style>

「3. 伪元素选择器」

图片

  • 伪元素选择器注意事项

    • before 和 after 必须有 content 属性

    • before 在内容前面,after 在内容后面

    • before 和 after 创建的是一个元素,但是属于行内元素

    • 创建出来的元素在 Dom 中查找不到,所以称为伪元素

    • 伪元素和标签选择器一样,权重为 1

<style>
    div {
      width: 100px;
      height: 100px;
      border: 1px solid lightcoral;
    }

    div::after,
    div::before {
      width: 20px;
      height: 50px;
      text-align: center;
      display: inline-block;
    }
    div::after {
      content: '德';
      background-color: lightskyblue;
    }

    div::before {
      content: '道';
      background-color: mediumaquamarine;
    }
  </style>

伪元素字体图标

p {
   position: relative;
   width: 220px;
   height: 22px;
   border: 1px solid lightseagreen;
   margin: 60px;

}
p::after {
  content: '\ea50';
  font-family: 'icomoon';
  position: absolute;
  top: -1px;
  right: 10px;
}

CSS3 盒子模型 

 CSS3中可以通过box-sizing来指定盒模型,有2个值:即可指定为content-box、border-box,这样我们计算盒子大小的方式就发生了改变。

可以分成两种情况:

1. box-sizing:content-box  盒子大小为width + padding + border (以前默认的)

2. box-sizing:border-box  盒子大小为width

如果盒子模型我们改为了box-sizing:border-box,那padding和border就不会撑大盒子了(前提padding和border不会超过width宽度)

CSS3 其他特性(了解) 

1. CSS3滤镜filter: 

filter CSS属性将模糊或颜色偏移等图形效果应用于元素。

filter: 函数();  例如 : filter:blur(5px); blur模糊处理 数值越大越模糊 需加单位px

2. CSS3 calc 函数:

calc() 此CSS函数让你在声明CSS属性值时执行一些计算。

width:calc(100% - 80px);

 括号里面可以使用 + - * /来进行计算。(运算符前后需加空格)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱编程的小疯子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值