gpt4 book ai didi

html - Bootstrap : how to truly center an image in a column?

转载 作者:行者123 更新时间:2023-12-02 20:04:55 25 4
gpt4 key购买 nike

我想使用 Bootstrap 将 4 张图像放入 4 个堆叠列中。这是我的代码:

<html>
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>

<body>
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<div class="row">
<div class="col-md-6" style="background-color:lavenderblush">
<img src="https://images.pexels.com/photos/60597/dahlia-red-blossom-bloom-60597.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" class="rounded" alt="flower" style="width:50%; margin-top: 10px; margin-bottom: 10px">
</div>
<div class="col-md-6" style="background-color:lavender;">
<img src="https://images.pexels.com/photos/60597/dahlia-red-blossom-bloom-60597.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" class="rounded" alt="flower" style="width:50%; margin-top: 10px; margin-bottom: 10px">
</div>
</div>
<div class="row">
<div class="col-md-6" style="background-color:lavender">
<img src="https://images.pexels.com/photos/60597/dahlia-red-blossom-bloom-60597.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" class="rounded" alt="flower" style="width:50%; margin-top: 10px; margin-bottom: 10px">
</div>
<div class="col-md-6" style="background-color:lavenderblush;">
<img src="https://images.pexels.com/photos/60597/dahlia-red-blossom-bloom-60597.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" class="rounded" alt="flower" style="width:50%; margin-top: 10px; margin-bottom: 10px">
</div>
</div>
</div>
</div>
</div>
</body>
</html>

4张图片左上角对齐(在大屏幕上),我想要的是将它们垂直和水平居中对齐,无论图像宽度或高度有任何变化,我该怎么做?我在网上进行了搜索,但似乎没有什么能真正解决问题。

最佳答案

或者你可以用 flexbox 来做。

添加到您的col-md-6

display: flex;
align-items: center;
justify-content: center

关于html - Bootstrap : how to truly center an image in a column?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55021316/

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