bootstrap 移动时的网格
bootstrap grid when mobile
在全屏模式下我不想使用 grid
我想显示 7 并且我想在移动设备中管理图像 2,2,2,1
我怎么能做这样的事情...
<div class="col-xs-6">
<img src="banner1.png" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="banner1.png" alt="" class="banner-img">
</div>
在我的 html 中看起来不错,但在移动时如何显示 2,2,2,1
<div class="container banner">
<img src="banner1.png" alt="" class="banner-img">
<img src="banner2.png" alt="" class="banner-img">
<img src="banner3.png" alt="" class="banner-img">
<img src="banner4.png" alt="" class="banner-img">
<img src="banner5.png" alt="" class="banner-img">
<img src=banner6.png" alt="" class="banner-img">
<img src="banner7.png" alt="" class="banner-img">
</div>
我认为你实际上指出了你自己的解决方案
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" ></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<style type="text/css">
img{
border:1px solid black;
}
</style>
</head>
<body>
<div class="container banner">
<div class="row">
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
</div>
</div>
</body>
</html>
基本上你需要做的就是玩CSS。在 Css 中使用 @media
并为 移动屏幕 设置横幅宽度。下面是完整的工作示例:
.banner {
background-color: red;
text-align: center;
vertical-align: middle;
width: 100%;
padding: 10px;
}
.banner-img {
margin-top: 25px;
margin-right: 5px;
width: 100px;
height: 100px;
}
@media only screen and (max-width: 500px) {
.banner-img {
width: 120px;
}
}
<div class="banner">
<div class="container banner">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
</div>
</div>
您可以根据屏幕尺寸调整横幅宽度。享受吧!
在全屏模式下我不想使用 grid
我想显示 7 并且我想在移动设备中管理图像 2,2,2,1
我怎么能做这样的事情...
<div class="col-xs-6">
<img src="banner1.png" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="banner1.png" alt="" class="banner-img">
</div>
在我的 html 中看起来不错,但在移动时如何显示 2,2,2,1
<div class="container banner">
<img src="banner1.png" alt="" class="banner-img">
<img src="banner2.png" alt="" class="banner-img">
<img src="banner3.png" alt="" class="banner-img">
<img src="banner4.png" alt="" class="banner-img">
<img src="banner5.png" alt="" class="banner-img">
<img src=banner6.png" alt="" class="banner-img">
<img src="banner7.png" alt="" class="banner-img">
</div>
我认为你实际上指出了你自己的解决方案
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" ></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<style type="text/css">
img{
border:1px solid black;
}
</style>
</head>
<body>
<div class="container banner">
<div class="row">
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
<div class="col-xs-6">
<img src="http://via.placeholder.com/150x150" alt="" class="banner-img">
</div>
</div>
</div>
</body>
</html>
基本上你需要做的就是玩CSS。在 Css 中使用 @media
并为 移动屏幕 设置横幅宽度。下面是完整的工作示例:
.banner {
background-color: red;
text-align: center;
vertical-align: middle;
width: 100%;
padding: 10px;
}
.banner-img {
margin-top: 25px;
margin-right: 5px;
width: 100px;
height: 100px;
}
@media only screen and (max-width: 500px) {
.banner-img {
width: 120px;
}
}
<div class="banner">
<div class="container banner">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
<img src="http://via.placeholder.com/50x50" alt="" class="banner-img">
</div>
</div>
您可以根据屏幕尺寸调整横幅宽度。享受吧!