博主信息
博文 14
粉丝 0
评论 0
访问量 15520
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
HTML伪类、盒子模型学习与应用
暮光薄凉
原创
817人浏览过

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>



批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学