Blogger Information
Blog 14
fans 0
comment 0
visits 11543
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
HTML伪类、盒子模型学习与应用
暮光薄凉
Original
563 people have browsed it

1. 伪类

:nth-of-type(3) 分组匹配,匹配前根据元素类型进行分类后在匹配,参数为分组的第几个元素
:not(p:nth-of-type(3)) 排除p分组中第3个p元素
:first-of-type 选择分组第1个元素
:last-of-type 选择分组的最后1个元素
:nth-last-of-type(3) 选择分组倒数第3个元素

伪类的参数计算
参数 = an + b
a : 系数 从1开始
n : 计数器 从0开始
b : 偏移量 从0开始

总结:
1.获取指定的某一个元素:(b)
2.获取前几个元素:(n-b)
3.获取指定位置后的全部元素:(n+b)
4.获取全部偶数:(2n/even)或奇数(2n+1/odd)元素

伪类示例:

  1. .lest > :nth-of-type(3){background: darksalmon;}/*选择分组的第三个元素*/
  2. .lest > li:nth-of-type(3){background: darksalmon;}/*选择li分组的第3个li元素*/
  3. .lest > :nth-of-type(3):not(p:nth-of-type(3)){background: darksalmon;}/*排除p分组中第3个p元素*/
  4. .lest > :first-of-type{background: darksalmon;}/*选择分组第1个元素*/
  5. .lest > :last-of-type{background: rgb(109, 46, 25);}/*选择分组最后一个元素*/
  6. .lest > :nth-last-of-type(3){background: rgb(231, 140, 110);}/*选择分组倒数第几个元素*/
  1. .lest > :nth-of-type(3n+2){background: rgb(112, 37, 13);}
  2. 分别作用于第2,5..个
  3. /*计算:
  4. 3 * 0 + 2 = 2
  5. 3 * 1 + 2 = 5
  6. ...
  7. */
  8. /*获取前几个元素*/
  9. .lest > :nth-of-type(-n+2){background: rgb(112, 37, 13);}
  10. /*获取最后几个元素*/
  11. .lest > :nth-last-of-type(-n+3){background: rgb(231, 140, 110);}
  12. /*获取偶数位置元素[2,4,6,...]*/
  13. .lest > :nth-of-type(2n){background: darksalmon;}
  14. .lest > :nth-of-type(even){background: darksalmon;}
  15. /*获取奇数位置元素[1,3,5,...]*/
  16. .lest > :nth-of-type(2n+1){background: rgb(112, 37, 13);}
  17. .lest > :nth-of-type(odd){background: rgb(112, 37, 13);}

2. 字体图标应用

  1. /*引入字体图标文件*/
  2. <link rel="stylesheet" href="./tubiao/iconfont.css">
  3. /*应用实例*/
  4. <span class="iconfont icon-pay-jingdong"><samp>京东</samp></span>
  5. <style>
  6. .iconfont{ font-size: 4rem;color: deeppink;}
  7. </style>

3.盒模型常用属性与应用

常用属性

  1. width:;/*宽*/
  2. height:;/*高*/
  3. border: ;/*边框*/
  4. margin: 0 0 0 0;/*外边距,顺序:上右下左*/
  5. padding:0 0 0 0 ;/*内边距,顺序:上右下左*/
  6. box-sizing: content-box;/*指定内容区边界*/
  7. box-sizing: border-box;/*通过收缩内容区大小,保证盒子在页面中占据的空间大小不变*/
  8. cursor: pointer;/*改变光标形状,使光标变成手指*/
  9. opacity: 0.8;/*变透明*/
  10. transition: 0.3s;/*控制变化时间*/
  11. @media/*查询语法*/
  12. @media (min-width:480px) {}/*最小480px*/
  13. @media (max-width:720px) {}/*最大720px*/

样式常用单位

  1. px/*绝对定位*/
  2. em,rem/*相对定位*/
  3. vw,vh/*可视化窗口大小*/
  4. 16px = 1em
  5. 16px = 1.6rem
  6. width:10vw;/*相当于占据当前可视窗口的10%*/

元素样式重置解决方案

  1. margin: 0;
  2. padding:0;
  3. box-sizing: border-box;

应用:

  1. <button class="moxing bj-1">imte</button>
  2. <button class="moxing bj-2">imte</button>
  3. <button class="moxing bj-3">imte</button>
  4. <style>
  5. html{font-size: 10px;}
  6. .moxing{
  7. border: 1px solid #777;
  8. background: burlywood;
  9. }
  10. .moxing.bj-1{font-size: 1.2rem;}
  11. .moxing.bj-2{font-size: 1.6rem;}
  12. .moxing.bj-3{font-size: 1.8rem;}
  13. @media (min-width:480px) {html{font-size: 12px;}}
  14. @media (min-width:640px) {html{font-size: 14px;}}
  15. @media (min-width:720px) {html{font-size: 16px;}}
  16. </style>



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