<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
body,a,p{
margin: 0;padding: 0;
}
.box{
max-width: 1100px;
min-width: 830px;
height: 320px;
margin: auto;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
}
.box a{
display: block;width: 200px;height: 150px;border-radius: 10px;overflow: hidden;text-decoration: none;
box-shadow: 0 0 3px;
}
.box a img{
width: 200px;height: 120px;
}
.box a p{
width: 200px;height: 30px;line-height: 30px;font-weight: 400;
text-align: center;color: black;
}
</style>
</head>
<body>
<div class="box">
<a href="#">
<img src="img/1.jpg" >
<p>我要自学网1</p>
</a>
<a href="#">
<img src="img/2.jpg" >
<p>我要自学网2</p>
</a>
<a href="#">
<img src="img/3.jpg" >
<p>我要自学网3</p>
</a>
<a href="#">
<img src="img/4.jpg" >
<p>我要自学网4</p>
</a>
<a href="#">
<img src="img/5.jpg" >
<p>我要自学网5</p>
</a>
<a href="#">
<img src="img/6.jpg" >
<p>我要自学网6</p>
</a>
<a href="#">
<img src="img/7.jpg" >
<p>我要自学网7</p>
</a>
<a href="#">
<img src="img/8.jpg" >
<p>我要自学网8</p>
</a>
<a href="#">
<img src="img/9.jpg" >
<p>我要自学网9</p>
</a>
<a href="#">
<img src="img/10.jpg" >
<p>我要自学网10</p>
</a>
</div>
</body>
</html>



flex弹性盒子子元素溢出 拖动浏览器 缩小后a元素跑出来了 求解
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- MafiaboyYang 2021-10-30 12:03关注
flex wrap 就是这样的,我提供你一种解决方案
b站的视频自动调整就是用的这种方法,我也是刚学前端一个星期,照着b站做了一个模仿界面,b站源码是这样解决的
1<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> body,a,p{ margin: 0;padding: 0; } .box{ max-width: 1100px; min-width: 830px; height: 320px; margin: auto; display: -webkit-flex; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: space-between; } .box a{ display: block;width: 200px;height: 150px;border-radius: 10px;overflow: hidden;text-decoration: none; box-shadow: 0 0 3px; } .box a img{ width: 200px;height: 120px; } .box a p{ width: 200px;height: 30px;line-height: 30px;font-weight: 400; text-align: center;color: black; } @media screen and (max-width: 1000px){ .box a:nth-child(n+9){ display: none; } } </style> </head> <body> <div class="box"> <a href="#"> <img src="vuex.png" > <p>我要自学网1</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网2</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网3</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网4</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网5</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网6</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网7</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网8</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网9</p> </a> <a href="#"> <img src="vuex.png" > <p>我要自学网10</p> </a> </div> </body> </html>  
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报