目标:
并且屏幕不够宽,请在第二行显示卡片。
我使用Bootstrap 4,目前,我的卡仅在一行上。我阅读了文档,并尝试了很多代码。目前,我不明白为什么我的卡太小而不尊重128px的大小。
结果是相同的网格系统响应。
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Hello</title>
</head>
<body class="text-center">
<div id='main-content' class="card-deck" style="margin: 50px 0 0 0">
<div class="card mb-4" style="max-width: 128px; max-width: 128px">
<a href="https://www.netflix.com/fr/"><img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img-top"></a>
</div><span></span>
<div class="card mb-4" style="width: 128px; height: 128px">
<a href="https://www.hulu.com"><img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img-top"></a>
</div><span></span>
<div class="card mb-4" style="width: 128px; height: 128px">
<a href="https://www.hulu.com"><img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img-top"></a>
</div><span></span>
<div class="card mb-4" style="width: 128px; height: 128px">
<a href="https://www.hulu.com"><img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img-top"></a>
</div><span></span>
<div class="card mb-4" style="width: 128px; height: 128px">
<a href="https://www.hulu.com"><img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img-top"></a>
</div><span></span>
<div class="card mb-4" style="width: 128px; height: 128px">
<a href="https://www.hulu.com"><img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img-top"></a>
</div><span></span>
<div class="card mb-4" style="width: 128px; height: 128px">
<a href="https://www.hulu.com"><img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img-top"></a>
</div><span></span>
<div class="card mb-4" style="width: 128px; height: 128px">
<a href="https://www.hulu.com"><img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img-top"></a>
</div><span></span>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
最佳答案
从card-deck
中取出卡片,然后将它们放入row
中。并且,如果您想将整个内容水平居中,则将justify-content-center
类添加到该行中(单击“运行代码按钮”,然后展开到整页):
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.card-custom {
max-width: 128px;
}
</style>
<div class="container">
<div class="row mt-5 justify-content-center">
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.netflix.com/fr/">
<img src="https://cdn1.iconfinder.com/data/icons/metro-ui-dock-icon-set--icons-by-dakirby/256/Netflix.png" alt="" class="card-img">
</a>
</div>
<div class="card card-custom mx-2 mb-3">
<a href="https://www.hulu.com">
<img src="https://apprecs.com/ios-meta/app-icons/256/376510438.jpg" alt="" class="card-img">
</a>
</div>
</div>
</div>
请注意,我还添加了
mx-2 mb-3
类来分隔间距。关于css - 如何在固定大小的多行上使用带有Bootstrap 4的卡?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48614243/