伪类选择器

权重同class一样

结构伪类:根据元素位置获取元素

  1. :first-of-type 获取第一个
    例:获取class为“list”的第一个子元素
    .list > item:first-of-type

  2. :last-of-type 获取最后一个
    例:获取class为“list”的最后一个子元素
    .list >item:first-of-type

  3. :nth-of-type(n) 获取任意一个
    n为几就获取第几个元素
    例:获取class为“list”的第3个子元素
    .list >item:nth-of-type(3)

  4. :nth-last-of-type(n) 获取倒数第几个元素
    n为几就获取倒数第几个元素
    例:获取class为“list”的倒数第2个子元素
    .list >item:nth-last-of-type(2)

伪类选择器的参数

:nth-of-type(an+b)
参数说明

参数说明取值
a系数从0开始
n从0开始
b偏移量从0开始
  1. 当a=0时,an+b=b,即偏移量是几就匹配第几个元素,属于单个元素匹配。

  2. 当a=1时,an+b=n+b,即取偏移量及之后的所有元素。
    例:.lsit > item:nth-of-type(n+2) 就是取第2个及之后的所有元素。

  3. 当a=-1时,an+b=-n+b,即取偏移量及之前的所有元素。
    例:.list > item:nth-of-type(-n+3) 即取前3个元素

  4. 当a=-1时,:nth-last-of-type(-n+b) 为取倒数几个元素。
    例:.list > item:nth-last-of-type(-n+3) 即取后3个元素

5.当an+b=2n+1时,为取奇数位的元素1,3,5,7,9…,可以简化为 “odd” 即: .list > item:nth-of-type(odd)

6.当an+b=2n时,为取偶数位的元素,2,4,6,8,10…,可以简化为 “even” 即:.list > item:nth-of-type(even)

引入字体图标的详细步骤

以引入阿里图标库为例:
第1步:将图标添加到购物车-下载代码
第2步:将代码解压复制到项目目录中,在项目中引入CSS文件
第3步:在元素中引入图标样式
例:```html
<span class="iconfont icon-shezhi"></span>

  1. ![](https://img.php.cn/upload/image/112/954/964/1641217831146287.jpg)
  2. # 盒模型的5个属性
  3. #### `box-sizing:` 值有两个:
  4. 1. border-box:边框、内边距和外边距都计算在width/height内,不会把盒子撑开。
  5. 2. content-box:边框、内外边距单独存在,会把盒子撑开。导致盒子整体的宽度和高度会变大。
  6. #### 五个属性:
  7. 1. width 宽度
  8. 2. height 高度
  9. 3. padding 内边距
  10. 4. margin 外边距
  11. 5. border 边框
  12. #### box-sizing两个取值的差异:
  13. 1. border-box:
  14. ```html
  15. .box {
  16. width: 20em;
  17. height: 20em;
  18. background-color: aquamarine;
  19. border: 5px solid red;
  20. box-sizing: border-box;
  21. padding: 3em;
  22. overflow: hidden;
  23. }



通过上图可以看出,box并没有被撑大,而是把内容区域缩小了。

  1. content-box:
    1. .box {
    2. width: 20em;
    3. height: 20em;
    4. background-color: aquamarine;
    5. border: 5px solid red;
    6. box-sizing: content-box;
    7. padding: 3em;
    8. overflow: hidden;
    9. }


    通过上图可以看出,box内容区域并没有变化,但是,边框内边距把box整体撑开了。

em , rem的区别

  • em与当前元素或父元素的font-size绑定
  • rem只与html(根元素)的font-size绑定

    1. <style>
    2. html {
    3. font-size: 20px;
    4. }
    5. .box {
    6. font-size: 16px;
    7. }
    8. .item {
    9. font-size: 2em;
    10. }
    11. .item2 {
    12. font-size: 2rem;
    13. }
    14. </style>
    15. <div class="box">
    16. <div class="item">
    17. PHP.cn中文网
    18. </div>
    19. <div class="item2">
    20. PHP.cn中文网
    21. </div>
    22. </div>




    通过上图可以看出,类为item的元素,字体为2em,与其父元素的font-size:16绑定,结果为32px;类为item2的元素,字体为2rem,与html的font-size:20px绑定,结果为40px。

更多相关文章

  1. Android(安卓)中的DisplayMetrics的用法
  2. Android(安卓)蓝牙开发研究
  3. Android布局文件属性笔记
  4. Android布局文件的属性值解析
  5. versionCode与versionName的区别、应用、获取
  6. Google Android应用开发04 Android应用程序结构
  7. Android(安卓)WIFI 学习整理+搜索到资料
  8. Android之布局
  9. 详解mysql 获取当前日期及格式化

随机推荐

  1. android 扫描SDCard.
  2. adb devices List of devices attached
  3. Android SDK更新失败及其解决办法
  4. ListView设置没有头部和底部分割线
  5. android build Communication error with
  6. android:configChanges screen
  7. android studio 修改生成的apk 包名
  8. Android收藏商品/关注商品
  9. android 进程内存分析
  10. android 窗口如何靠左和靠右边框布局