HTML代码:
<!DOCTYPE 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">
<title>css实现图片排版效果</title>
<link rel="stylesheet" href="./ceshi.css">
</head>
<body>
<!--
css图片自适应模板
-->
<div class="centent">
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
<div class="main">
<div class="img">
<img src="https://lib.microa.cn/static/images/shuffling.jpg" >
</div>
</div>
</div>
</body>
</html>
CSS代码:
body {
padding: 15px;
min-width: 320px;
}
.img>img {
width: 100%;
height: 100%;
border-radius: 5px;
object-fit: cover;
}
.img {
display: flex;
width: 90%;
height: 90%;
align-items: center;
border-radius: 5px;
}
.main {
display: flex;
justify-content: center;
align-items: center;
width: 25%;
height: 250px;
max-width: 25%;
}
.centent {
display: flex;
flex-wrap: wrap;
width: 100%;
height: auto;
min-height: 320px;
}
@media screen and (max-width: 1000px) {
.main {
display: flex;
justify-content: center;
align-items: center;
width: 33.3%;
height: 250px;
max-width: 33.3%;
}
body {
padding: 5px;
}
}
@media screen and (max-width: 756px) {
.main {
display: flex;
justify-content: center;
align-items: center;
width: 50%;
height: 250px;
max-width: 50%;
}
body {
padding: 8px;
}
}
@media screen and (max-width: 500px) {
body {
padding: 3px;
}
}
@media screen and (max-width: 350px) {
body {
padding: 0px;
}
}
文章来源地址https://www.toymoban.com/news/detail-511281.html
文章来源:https://www.toymoban.com/news/detail-511281.html
到了这里,关于使用CSS实现简单的图片自适应UI模板代码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!