Blogger Information
Blog 7
fans 0
comment 1
visits 1801
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
这是第五天学习CSS的知识
学,无止尽
Original
188 people have browsed it

这是我学习的第五天

CSS结构伪类

1.查询路口:七点,可以是父级,也可以是起始兄弟,仅限子元素或同级兄弟,尽量用’>’只有一级用空格

传统:class叠加

  1. .list > .item.first {
  2. background-color: blueviolet;
  3. }
  4. .list > .item.last {
  5. background-color: blueviolet;
  6. }
  7. .list > .item.four {
  8. background-color: blueviolet;
  9. }

效果图

伪类 :nth-child(an+b): 获取任意位置的元素

  1. .list > .item:nth-child(1) {
  2. background-color: blueviolet;
  3. }
  4. .list > .item:nth-child(9) {
  5. background-color: blueviolet;
  6. }
  7. .list > .item:nth-child(4) {
  8. background-color: blueviolet;
  9. }

效果图

获取第一个和最后一个属于高频操作,有快捷的语法糖

  1. .list > .item:first-child {
  2. background-color: blueviolet;
  3. }
  4. .list > .item:last-child {
  5. background-color: blueviolet;
  6. }

效果图

获取前三个

  1. .list > .item:nth-child(3) {
  2. background-color: blueviolet;
  3. }
  4. .list > .item:nth-child(2) {
  5. background-color: blueviolet;
  6. }
  7. .list > .item:nth-child(1) {
  8. background-color: blueviolet;
  9. }

· 效果图

也可以使用语法糖

  1. /* .list > .item:nth-child(-n + 3) {
  2. background-color: blueviolet;
  3. }
  • 效果是一样的
    获取最后3个
    1. .list > .item:nth-last-child(-n + 3) {
    2. background-color: blueviolet;
    3. }
  • 效果图

    从1-3选择
    1. .list > .item:nth-child(-n + 3) {
    2. background-color: violet;
    3. }
  • 效果图
  • 选择最后3个,nth后面加上倒数属性:last
    ```css
    .list > .item:nth-last-child(-n + 3) {
    background-color: violet;
    }
  • 效果图
    1. (偶数选择):2n = even
    2. ```css
    3. .list > .item:nth-child(even) {
    4. background-color: violet;
    5. }
  • 效果图

    (奇数选择):2n+1,2n-1都可以,一样
    1. .list > .item:nth-child(odd) {
    2. background-color: violet;
    3. }
  • 效果图

    固定间隔选择,可用偏移量可进行微调,可正可负
    1. .list > .item:nth-child(3n) {
    2. background-color: violet;
    3. }
  • 效果图
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:总结的不错,继续加油
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!