1.使用CSS3来DIY图片i无缝轮播效果:图片大小:126*86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用css3动画制作自动无缝轮播图</title>
<style>
body, ul, li {
margin: 0;
padding: 0;
}
img {
border: 0 none;
vertical-align: top;
}
.warp {
width: 882px;
/*width: 126px;*/
height: 86px;
border: 1px solid #000;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
overflow: hidden;
}
ul:hover {
/*动画的播放状态
使用这个属性能够改变动画的播放状态,
如动画正在播放时,
可以通过这个属性,
让动画暂停一下*/
animation-play-state: paused;
}
ul {
list-style: none;
width: 1800px;
/*动画名称 必写*/
animation-name: dong;
/*动画一次所持续的时间 必写*/
animation-duration: 2000ms;
/*动画执行的次数(动画重复的次数) 无数次:infinite;*/
animation-iteration-count: infinite;
/*动画的方向:normal 全正向,alternate 先正向再反向*/
animation-direction: normal;
/*动画结束后保持的状态 backwards(默认值)表示回退到原点
forwards表示不回到原点,backwards表示动画结束后 保持 动画开始前的状态,
forwards表示动画结束后 保持 动画结束后状态*/
animation-fill-mode: backwards;
/*动画的类型 也就是动画的运动曲线
linear 表示线性匀速
ease-in 表示慢慢变快
ease-in-out 表示先快后慢
steps(3) 表示每一次动画都是分三步完成(速度就像是一帧一帧的完成的),
steps这个属性可以用来做时钟,
也能够用来做那些 很准确的一帧一帧完成的动画,
因为steps的每一帧都是瞬间完成的*/
animation-timing-function: linear;
/*动画每次执行时延迟的时间*/
animation-delay: 0s;
}
li {
float: left;
}
@keyframes dong {
from {
}
to {
transform: translate(-882px, 0);
}
}
</style>
</head>
<body>
<div class="warp">
<ul>
<li><img src="images/1.jpg"></li>
<li><img src="images/2.jpg"></li>
<li><img src="images/3.jpg"></li>
<li><img src="images/4.jpg"></li>
<li><img src="images/5.jpg"></li>
<li><img src="images/6.jpg"></li>
<li><img src="images/7.jpg"></li>
<li><img src="images/1.jpg"></li>
<li><img src="images/2.jpg"></li>
<li><img src="images/3.jpg"></li>
<li><img src="images/4.jpg"></li>
<li><img src="images/5.jpg"></li>
<li><img src="images/6.jpg"></li>
<li><img src="images/7.jpg"></li>
</ul>
</div>
</body>
</html>
2.使用CSS3来DIY立体导航栏效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>使用css3中的transform制作立体导航栏</title>
<style>
body,ul,li {
margin: 0;
padding: 0;
}
body {
background-color: deeppink;
}
ul {
width: 900px;
margin: 100px auto;
height: 80px;
list-style: none;
position: relative;
}
ul li {
width: 180px;
height: 80px;
cursor: pointer;
float: left;
}
li span {
float: left;
height: 80px;
background-color: #ccc;
}
span.left {
width: 30px;
height: 80px;
transform-origin: left;
}
span.center {
width: 120px;
height: 80px;
text-align: center;
font: 500 20px/80px "Microsoft yehei";
/*color: white;*/
}
span.right {
width: 30px;
height: 80px;
transform-origin: right;
}
li:hover span.left {
transform: skew(0deg, -30deg);
background-color: #c0c0c0;
}
li:hover span.center {
transform: translateY(-18px);
text-shadow:5px 5px 3px #333;
box-shadow: 0 15px 20px -4px #666;
}
li:hover span.right {
transform: skew(0deg, 30deg);
background-color: #c0c0c0;
}
ul::before,ul::after {
content:"";
position: absolute;
z-index: -1;
/*width: 450px;*/
width: 30px;
height: 80px;
left: -30px;
/*background-color: #e0e0e0;*/
background-color: #ccc;
}
ul:after {
left: auto;
right: -30px;
}
</style>
</head>
<body>
<ul>
<li>
<span class="left"></span>
<span class="center">水晶女孩</span>
<span class="right"></span>
</li>
<li>
<span class="left"></span>
<span class="center">水晶女孩</span>
<span class="right"></span>
</li>
<li>
<span class="left"></span>
<span class="center">水晶女孩</span>
<span class="right"></span>
</li>
<li>
<span class="left"></span>
<span class="center">水晶女孩</span>
<span class="right"></span>
</li>
<li>
<span class="left"></span>
<span class="center">水晶女孩</span>
<span class="right"></span>
</li>
</ul>
</body>
</html>
3.CSS3新增的伸缩布局,主轴方向是从左到右,侧轴方向是从上到下:
◆
display:flex;
默认从左到右,从上到下
◆设置主轴排列方向的方式:,
flex-direction:row;
(默认属性,表示从左至右的排列),
flex-direction:row-reverse;
(表示从右至左的排列),
flex-direction:column;
(表示从上到下的排列),
flex-direction:column-reverse;
(表示从下到的排列),
最重要的是横向排列时,当所有子元素的宽小于父容器的宽时,子元素多宽就是多宽,但是如果所有子元素的宽大于父容器了,那么就会自适应父容器的宽,于是子元素原来的宽就无效了,子元素的宽度就变成父容器除以子容器的个数的值了,当然如果有外边距也会加进去用来计算,纵向排列也是如此,但是如果父容器没有设置高,那就不会自适应父容器的高了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css3中的伸缩布局(主轴排列方向的方式)</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
font: 400 22px "Microsoft yehei";
background-color: #eee;
}
h3 {
font-weight: normal;
}
section {
width: 1000px;
margin: 40px auto;
}
ul {
list-style: none;
border: 1px solid #ccc;
background-color: #fff; height:500px;
}
ul li {
width: 200px;
height: 200px;
background-color: #0ff;
box-sizing: border-box;
margin: 10px;
}
section:nth-child(1) ul {
overflow: hidden;
}
section:nth-child(1) ul li {
float: left;
}
section:nth-child(2) ul {
display: flex;
}
section:nth-child(3) ul {
display: flex;
flex-direction: row;
}
section:nth-child(4) ul {
display: flex;
flex-direction: row-reverse;
}
section:nth-child(5) ul {
display: flex;
flex-direction: column;
}
section:nth-child(6) ul {
display:flex;
flex-direction:column-reverse;
}
section:nth-child(7) ul {
text-indent:2em;
color:#daa520;
}
</style>
</head>
<body>
<section>
<h3>传统布局方式</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>伸缩布局方式 display:flex</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>伸缩布局方式(设置主轴方向的方式) flex-direction:row;(默认属性,表示从左至右的排列)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>伸缩布局方式(设置主轴方向的方式) flex-direction:row-reverse;(表示从右至左的排列)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>伸缩布局方式(设置主轴方向的方式) flex-direction:column;(表示从上到下的排列)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>伸缩布局方式(设置主轴方向的方式) flex-direction:column-reverse;(表示从下到的排列)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>小总结</h3>
<ul>
最重要的
是横向排列时,当所有子元素的宽小于父容器的宽时,子元素多宽就
是多宽,但是如果所有子元素的宽大于父容器了,那么就会自适应父
容器的宽,于是子元素原来的宽就无效了,子元素的宽度就变成父容
器除以子容器的个数的值了,当然如果有外边距也会加进去用来计算
,纵向排列也是如此,但是如果父容器没有设置高,那就不会自适应
父容器的高了。
</ul>
</section>
</body>
</html>
◆设置主轴对齐的方式:
justify-content:flex-start
(表示对齐方式是从主轴方向开始的地方对齐),
justify-content:flex-end
(表示对齐方式是从主轴方向结束的地方对齐),
justify-content:center
(表示对齐方式是从主轴方向中间的地方对齐),
justify-content:space-round
(表示对齐方式是从主轴方向空间平分),
justify-content:space-between
(表示对齐方式是从主轴方向两端对齐中间的居中)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css3中的伸缩布局(设置主轴对齐的方式)</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
font: 400 22px "Microsoft yehei";
background-color: #eee;
}
h3 {
font-weight: normal;
}
section {
width: 1000px;
margin: 40px auto;
}
ul {
list-style: none;
border: 1px solid #ccc;
background-color: #fff; height:500px;
}
ul li {
width: 200px;
height: 200px;
background-color: #0ff;
box-sizing: border-box;
margin: 10px;
}
section:nth-child(1) ul {
display: flex;
/*justify :整理*/
justify-content: flex-start;
}
section:nth-child(2) ul {
display: flex;
justify-content: flex-end;
}
section:nth-child(3) ul {
display: flex;
justify-content: center;
}
section:nth-child(4) ul {
display: flex;
/*space:空间*/
/*around:四周 周围*/
justify-content: space-around;
}
section:nth-child(5) ul {
display: flex;
justify-content: space-between;
}
</style>
</head>
<body>
<section>
<h3>justify-content:flex-start(表示对齐方式是从主轴方向开始的地方对齐)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>justify-content:flex-end(表示对齐方式是从主轴方向结束的地方对齐)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>justify-content:center(表示对齐方式是从主轴方向中间的地方对齐)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>justify-content:space-round(表示对齐方式是从主轴方向空间平分)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>justify-content:space-between(表示对齐方式是从主轴方向两端对齐中间的居中)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
</body>
</html>
◆侧轴对齐的方式:
align-items:flex-start
(表示对齐方式是从侧轴方向开始的地方对齐),
align-items:flex-end
(表示对齐方式是从侧轴方向结束的地方对齐),
align-items:center
(表示对齐方式是从侧轴方向中间的地方对齐),
align-items:baseline
(表示对齐方式是从侧轴方向基线的地方对齐,与flex-start一样),
align-items:stretch
(表示对齐方式是从侧轴方向的以拉伸的方式对齐,只要子元素的高度为auto,那么会自适应父容器的高度,既拉伸)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>css3中的伸缩布局(设置侧轴对齐的方式)</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
font: 400 22px "Microsoft yehei";
background-color: #eee;
}
h3 {
font-weight: normal;
}
section {
width: 1000px;
margin: 40px auto;
}
ul {
list-style: none;
border: 1px solid #ccc;
background-color: #fff;
height: 500px;
}
ul li {
width: 200px;
height: 200px;
background-color: #0ff;
box-sizing: border-box;
margin: 10px;
}
section:nth-child(1) ul {
display: flex;
align-items: flex-start;
}
section:nth-child(2) ul {
display: flex;
align-items: flex-end;
}
section:nth-child(3) ul {
display: flex;
align-items: center;
}
section:nth-child(4) ul {
display: flex;
align-items: baseline;
}
section:nth-child(5) ul {
display: flex;
/*stretch:伸展*/
align-items:stretch;
}
section:nth-child(5) ul li{
height: auto;
}
</style>
</head>
<body>
<section>
<h3>align-items:flex-start(表示对齐方式是从侧轴方向开始的地方对齐)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>align-items:flex-end(表示对齐方式是从侧轴方向结束的地方对齐)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>align-items:center(表示对齐方式是从侧轴方向中间的地方对齐)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>align-items:baseline(表示对齐方式是从侧轴方向基线的地方对齐,与flex-start一样)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</section>
<section>
<h3>align-items:stretch(表示对齐方式是从侧轴方向的以拉伸的方式对齐,只要子元素的高度为auto,那么会自适应父容器的高度,既拉伸)</h3>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
&