我正在使用引导卡在下面创建基本图像和文本。决定使用卡类,因为它的结构非常好,并且不想使用太多的CSS来水平制作div列表。我想要的是像这样的水平滚动图像库
问题在于,当我添加更多卡时,卡行为会变小。这是什么问题? ,也许我不应该使用卡组?也许必须取消引导程序并编写自己的引导程序?
.card-group {
overflow-x: scroll;
white-space: nowrap;
max-width: 30rem;
padding: 1rem;
}
<!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>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49"
crossorigin="anonymous"></script>
<script src="./index.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
crossorigin="anonymous">
</head>
<body>
<div class="container mt-4">
<div class="horzontal-scrollgallery">
<div class="card-group">
<div class="card pr-3">
<img class="card-img-top" src="./images/chicago.jpg" alt="Card image">
<div class="card-body text-center">
<h4 class="card-title">John Doe</h4>
</div>
</div>
<div class="card pr-3">
<img class="card-img-top" src="./images/chicago.jpg" alt="Card image">
<div class="card-body text-center">
<h4 class="card-title">John Doe</h4>
</div>
</div>
<div class="card pr-3">
<img class="card-img-top" src="./images/chicago.jpg" alt="Card image">
<div class="card-body text-center">
<h4 class="card-title">John Doe</h4>
</div>
</div>
<div class="card pr-3">
<img class="card-img-top" src="./images/chicago.jpg" alt="Card image">
<div class="card-body text-center">
<h4 class="card-title">John Doe</h4>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
</body>
</html>
答案 0 :(得分:3)
卡片变小的原因是,.card-group
显示为flex
,并且卡片项目的flex-grow
设置为1,这意味着它们将占用相等的宽度:
要获得所需的内容,您可以定义一个自定义类及其默认的.card-group
(这样就不会覆盖默认的卡组样式),设置其溢出样式以及其子级{ {1}}的{{1}},以便它们具有默认宽度。您需要将卡组的包装样式设置为<card>
,并且默认设置为flex-basis
。
no-wrap