gpt4 book ai didi

html - Bootstrap 4卡水平滚动问题?

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:04 25 4
gpt4 key购买 nike

我正在使用 bootstrap card 在下面创建基本图像和文本。决定使用 card 类,因为它的结构非常好,并且不想使用太多的 css 来水平制作 div 列表。我想要的是像这样的水平滚动的图片库 enter image description here

问题是当我添加更多卡片时卡片行为会变小。这里有什么问题? ,也许我不应该使用卡片组?可能必须放弃 Bootstrap 并自己编写?

.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>

最佳答案

你的卡片变小的原因是因为.card-group显示为 flex及其卡片元素' flex-grow设置为 1,这意味着它们将占用相同的宽度:

enter image description here

enter image description here

为了得到你想要的,你可以定义一个自定义类及其默认值 .card-group (这样你就不会覆盖默认的卡片组样式),设置它的溢出样式以及它的 child <card>flex-basis以便它们具有默认宽度。您需要将 card-group 的环绕样式设置为 no-wrap以及默认设置wrap .

CSS

@media (min-width: 576px) {
.card-group.card-group-scroll {
overflow-x: auto;
flex-wrap: nowrap;
}

.card-group.card-group-scroll > .card {
flex-basis: 35%;
}
}

结果

enter image description here

fiddle : http://jsfiddle.net/b2jw13go/1/

关于html - Bootstrap 4卡水平滚动问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53109202/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com