伪类,选择器语法,浮动基本使用

132 阅读1分钟

border-radius:5px【设置圆角的属性,值越大 角余额圆】 outline:none 

outline:none

height:19px 

[]中括号叫属性选择器 如果属性值存在,等特殊字符需要加引号 

【选取有herf属性的a元素】a[href]{background-color:color:red;} 

【选取href属性值等于www.baidu.cn的a元素,如果属性值存在.等特殊字符需要加引号】 a[href='www.baidu.cn']{background-color: red;} 【href的属性值以www开头的a元素】 a[href^=http]{background-color: red;}

 【href的属性值以cn结尾的a元素】a[href$=".cn"]{background-color: red;} 

<img src="./1.jfif" alt="图片加载中" (设置样式width 200px height 200px) > 

 【选取含有src的img图片】 img[src]{width: 200px;height: 200px;} 

【选取含有src=./1.jfif 的img图片】 img[src="./1.jfif"]{width: 200px;height: 200px;} 

 【选取含有alt以图字开头的img图片】 img[alt^="图"]{width: 200px;height: 200px;} 

 【选取含有alt以中字结尾的img图片】 img[alt$="中"]{width: 200px;height: 200px;} 

【选取含有alt中包含加字的img图片】 img[alt*="加"]{width: 200px;height: 200px;} 

ul .a+li{border:2px solid red;} +的意思是选择class为.a的元素同级的下一个li元素

 ul .b~li{border:2px solid red}~的意思是选择class为b的元素同级的所有的li元素

  .a > li{ 

  .a li{ 

  .a > li:nth-child(1) + li{ 

  .a > li:nth-child(1) ~ li{

【四种清除浮动方式】

overflow:hidden【把超出的内容截断】

.box{overflow:hidden} 

 .box::after{content: '里面内容会显示到页面上';display: block;clear:both;} 

 .a,.b{设置同一属性} 

在父盒子里面添加一个div 设置

 

float:left【消除display的缝隙 脱离标志流布局】

 第一种是给父盒子添加属性overflow:hidden,但是如果是下拉列表的情况 超出的会隐藏

 第二种是给父盒子固定高度,但是子盒子变多会溢出 

第三种是在父盒子里面添加一个div,设置clear:both清楚两边的浮动即可 

           但是会多出一个div元素,显得很多余 

第四种清楚浮动的方法、伪类