清除浮动最好的方式
<style>
.clearfix::after{
content: "";
display: block;
clear: both;
}
.box{
width: 200px;
border: 10px solid #000;
}
.box .box1{
float: left;
width: 100px;
height: 100px;
background-color: green;
}
.box .box2{
float: left;
width: 100px;
height: 100px;
background-color: orange;
}
</style>
<div class="box clearfix">
<div class="box1"></div>
<div class="box2"></div>
</div>
因为不是所有div、ul都需要清除浮动,如果所有div都加html太大了,没有必要
content
<style>
p::before{
/* content: url(img/icon.png); */
content: url(https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png);
margin-right: 5px;
vertical-align: middle;
width: 5px;
height: 5px;
}
</style>
<p>请点击发送信息</p>
加小图标可以用before
<style>
p::before {
content: attr(data-username);
}
</style>
<p data-username="enjoy">,欢迎您再次来到本网站。</p>
css3
盒子阴影
box-shadow:水平位置(必)垂直位置(必)
模糊距离 阴影尺寸 阴影颜色 阴影的种类
<style>
.box1{
width: 200px;
height: 100px;
margin: 100px;
background-color: orange;
box-shadow: 20px 10px;
}
</style>
<div class="box1"></div>
<style>
.box1{
width: 200px;
height: 100px;
margin: 100px;
background-color: orange;
/* box-shadow: 20px 10px; */
/* box-shadow: 0px 10px;
box-shadow: 20px 0; */
box-shadow: -10px -20px;
}
</style>
<div class="box1"></div>
<style>
.box1{
width: 200px;
height: 100px;
margin: 100px;
background-color: orange;
/* box-shadow: 20px 10px; */
/* box-shadow: 0px 10px;
box-shadow: 20px 0; */
/* box-shadow: -10px -20px; */
box-shadow: 10px 10px 20px;
}
</style>
<div class="box1"></div>
模糊距离20px也可以看作清晰度,越小越清晰,
<style>
.box1{
width: 200px;
height: 100px;
margin: 100px;
background-color: orange;
/* box-shadow: 20px 10px; */
/* box-shadow: 0px 10px;
box-shadow: 20px 0; */
/* box-shadow: -10px -20px; */
/* box-shadow: 10px 10px 20px; */
box-shadow: 10px 10px 5px 5px;
}
.box2{
width: 200px;
height: 100px;
margin: 100px;
background-color: orange;
/* box-shadow: 20px 10px; */
/* box-shadow: 0px 10px;
box-shadow: 20px 0; */
/* box-shadow: -10px -20px; */
/* box-shadow: 10px 10px 20px; */
box-shadow: 15px 15px 5px;
}
.box3{
width: 200px;
height: 100px;
margin: 100px;
background-color: orange;
box-shadow: 0 0 10px 10px;
/* box-shadow: 0 -15px 10px 10px ; */
/*阴影就上去了*/
}
</style>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
.box3{
width: 200px;
height: 100px;
margin: 100px;
background-color: orange;
/* box-shadow: 0 0 10px 10px; */
/* box-shadow: 0 -15px 10px 10px ; */
/*阴影就上去了*/
box-shadow: 0 15px 10px 10px #f40 inset;
}
遮住阴影
1设置position: relative
2z-index: 1;
<style>
body{
margin: 0;
}
.header{
/* position: relative; */
/* z-index因为没有position没有用处*/
z-index: 1;
width: 100%;
height: 60px;
background-color: yellow;
}
.box{
width: 300px;
height: 200px;
background-color: orange;
margin-left: 200px;
box-shadow: 0 0 30px #666;
}
</style>
<div class="header"></div>
<div class="box"></div>
<style>
body{
margin: 0;
}
.header{
position: relative;
z-index: 1;
width: 100%;
height: 60px;
background-color: yellow;
}
.box{
width: 300px;
height: 200px;
background-color: orange;
margin-left: 200px;
box-shadow: 0 0 30px #666;
}
</style>
<div class="header"></div>
<div class="box"></div>
京东也是这么做的
box-shadow: 0 0 30px #000;
-webkit-box-shadow:0 0 30px #000;
-moz-box-shadow:0 0 30px #000;
-o-box-shadow:0 0 30px #000;
浏览器兼容
圆角
<style>
.box{
width: 200px;
height: 100px;
background-color: orange;
border-radius: 20px;
}
</style>
<div class="box"></div>
<style>
.box1 {
width: 200px;
height: 200px;
background-color: orange;
border-radius: 50%;
/* 这样是圆形,width、height一样,radius是50%
纯圆 50% 宽高一样 */
}
.box2{
width: 200px;
height: 100px;
background-color: orange;
border-radius: 50px;
/* 这样圆角合起来是一个圆形
半圆角 height/2+px */
}
</style>
<div class="box1"></div>
<div class="box2"></div>
兼容性
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-o-border-radius: 50%;
图片圆角遮罩
<style>
.box{
width: 440px;
height: 248px;
border: 1px solid #000;
border-radius: 20px;
}
img{
width: 100%;
}
</style>
<div class="box">
<img src="https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg" alt="">
</div>
<style>
.box{
width: 440px;
height: 248px;
border: 1px solid #000;
border-radius: 20px;
overflow: hidden;
/* 溢出隐藏 */
}
img{
width: 100%;
}
</style>
<div class="box">
<img src="https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg" alt="">
</div>
到公司,做项目没有那么多时间去研究这些问题,这些经验,记在脑子里,到公司,不要为这些事情费时间
背景图片
<style>
.box{
width: 300px;
height: 300px;
margin: 100px;
border: 1px solid #000;
background-image: url(https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg);
/* background-size: 300px 300px; */
/* background-size: 100%; */
background-size: 50% 50%;
}
</style>
<div class="box"></div>
<style>
.box{
width: 300px;
height: 300px;
margin: 100px;
border: 1px solid #000;
background-image: url(https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg);
/* background-size: 300px 300px; */
/* background-size: 100%; */
background-size: 50% 50%;
background-repeat: no-repeat;
/* background-repeat:repeat|no-repeat|repeat-x|repeat-y*/
/* background-position: center; */
/* background-position: 50% 50%; */
/* background-position: top right; */
background-position: center center;
/* background-position:left top|left bottom|right top|right bottom|
center center|center bottom|center top|left center|right center |
50px 50px|50% 50%*/
}
</style>
<div class="box"></div>
<style>
.box{
width: 300px;
height: 300px;
margin: 100px;
border: 1px solid #000;
background:green url(https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg) no-repeat
center center/30% 30% ;
background:green url(https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg) no-repeat
center center/30% 30% ;
background:green url(https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg)
0 0/50% 50% no-repeat;
background:green url(https://wx1.sinaimg.cn/mw690/002p2Zyzly1h1hbucstg2j62bc334b2d02.jpg) no-repeat
0 0/30% 30% ;
}
</style>
<div class="box"></div>
<style>
body{
margin: 0;
}
.banner{
width: 100%;
height: 600px;
background-color: orange;
background-image: url(https://gw.alicdn.com/imgextra/i3/O1CN01iyYdem1GQd1yGgA0a_!!6000000000617-0-tps-2500-600.jpg);
background-size: 100% 100%;
/* background-size: cover; */
}
</style>
<div class="banner"></div>
图片随着浏览器大小变化而变化,被挤压,变形,分辨率变了
<style>
body{
margin: 0;
}
.banner{
width: 100%;
height: 600px;
background-color: orange;
background-image: url(https://gw.alicdn.com/imgextra/i3/O1CN01iyYdem1GQd1yGgA0a_!!6000000000617-0-tps-2500-600.jpg);
/* background-size: 100% 100%; */
background-size: cover;
background-position: center center;
}
</style>
<div class="banner"></div>
图片不会变化,缩放
<style>
body{
margin: 0;
}
.banner{
width: 100%;
height: 600px;
background-color: orange;
background-image: url(https://gw.alicdn.com/imgextra/i3/O1CN01iyYdem1GQd1yGgA0a_!!6000000000617-0-tps-2500-600.jpg);
/* background-size: 100% 100%; */
/* background-size: cover; */
/* 必须正好占满整个格子,会剪裁 */
background-repeat: no-repeat;
background-size: contain;
/*无论浏览器大小怎么变化,都会显示整个图片,会缩放*/
background-position: center center;
}
</style>
<div class="banner"></div>
背景图片不跟着滚动
<style>
/* 滚动内容发生变化,但背景图片不跟着滚动 */
html{
height: 100%;
background-color: green;
background-image: url(https://tse1-mm.cn.bing.net/th/id/R-C.5d978fd5d0a0a7252848708424ecdb92?rik=wRSxCwIkPjiigw&pid=ImgRaw&r=0);
background-size: 100% 100%;
background-attachment: fixed;
/* background-attachment: scroll|fixed */
}
</style>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>111111<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>222222<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>333333<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<style>
html{
height: 100%;
/* background-color: green;
background-image: url(https://tse1-mm.cn.bing.net/th/id/R-C.5d978fd5d0a0a7252848708424ecdb92?rik=wRSxCwIkPjiigw&pid=ImgRaw&r=0);
background-size: 100% 100%;
background-attachment: fixed; */
/* background-attachment: scroll|fixed */
/* background: background-color background-image background-repeat
background-attachment background-position/background-size */
background: green url(https://tse1-mm.cn.bing.net/th/id/R-C.5d978fd5d0a0a7252848708424ecdb92?rik=wRSxCwIkPjiigw&pid=ImgRaw&r=0)
no-repeat fixed 0 0/100% 100%;
}
</style>
<style>
html{
height: 100%;
/* background-color: green;
background-image: url(https://tse1-mm.cn.bing.net/th/id/R-C.5d978fd5d0a0a7252848708424ecdb92?rik=wRSxCwIkPjiigw&pid=ImgRaw&r=0);
background-size: 100% 100%;
background-attachment: fixed; */
/* background-attachment: scroll|fixed */
/* background: background-color background-image background-repeat
background-attachment background-position/background-size */
/* 分开写比较好,清楚一目了然,但公司可能要求写一块 */
background: green url(https://tse1-mm.cn.bing.net/th/id/R-C.5d978fd5d0a0a7252848708424ecdb92?rik=wRSxCwIkPjiigw&pid=ImgRaw&r=0)
no-repeat fixed 0 0/100% 100%;
}
</style>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>111111<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>222222<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br>333333<br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>