一、用弹性盒子练习
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
html {
height: 100%;
width: 100%;
}
body {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
ul {
width: 600px;
height: 300px;
list-style: none;
border: 1px solid red;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: stretch;
justify-content: space-around;
align-content: space-evenly;
background: #b1d8f8;
}
ul li {
width: 30%;
height: 30%;
border: 1px solid #008080;
list-style: none;
}
img {
width: 100%;
height: 100%;
display: flex;
list-style: none;
}
</style>
</head>
<body>
<ul>
<li><img src="11.jpg" alt=""></li>
<li><img src="11.jpg" alt=""></li>
<li><img src="11.jpg" alt=""></li>
<li><img src="11.jpg" alt=""></li>
<li><img src="11.jpg" alt=""></li>
<li><img src="11.jpg" alt=""></li>
</ul>
</body>
</html>
效果图
无论窗口大小改变图片不出边界。
案例二:
<IDOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
* {
padding: 0;
margin: 0;
}
html {
height: 100%;
width: 100%;
}
body {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
ul {
width: 560px;
height: 400px;
list-style: none;
border: 1px solid red;
display: flex;
flex-wrap: nowrap;
align-items: center;
/* justify-content:space-around; */
justify-content: space-evenly;
}
ul li {
width: 200px;
height: 0px;
border: 1px solid blue;
}
ul li:nth-child(2) {
width: 100px;
height: 80px;
display: flex;
border: 3px solid red;
color: red;
text-align: center;
/* line-height: 80px;*/
align-items: center;
justify-content: center;
}
</style>
</head>
<body>
<ul>
<li></li>
<li>中秋节快乐</li>
<li></li>
</ul>
</body>
</html>
利用弹性盒子做出图形