html - 三个图像居中,并排,位于页面中间
问题描述
我试图将 3 张图像并排居中放在页面中间,但我似乎无法完成最后一部分。我的代码:
<!DOCTYPE html>
<html>
<title>Exercise #1: Problem 5</title>
<head>
<style>
* {
box-sizing: border-box;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
text-align: center;
display: flex;
justify-content: center;
}
</style>
</head>
<body>
////some other code not related
<div class="row">
<div class="column">
<img src="https://previews.123rf.com/images/belchonock/belchonock1802/belchonock180284998/96079443-small-baby-carrots-in-plate-on-white-background.jpg" alt="Carrots" style="width:100%">
</div>
<div class="column">
<img src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/cucumber-slice-royalty-free-image-153556336-1562870568.jpg?crop=0.66682xw:1xh;center,top&resize=480:*" alt="Cucumbers" style="width:100%">
</div>
<div class="column">
<img src="https://img.freepik.com/free-photo/organic-background-green-vegetarian-nutrition_1203-5845.jpg?size=626&ext=jpg" alt="Cabbage" style="width:100%">
</div>
</div>
<hr>
</body>
</html>
如何将其更改为仅 html 以及如何将图像放在页面中间?
解决方案
在引导程序的帮助下,你可以很容易地做到这一点。
<div class="d-flex justify-content-center">
<div class="row">
<div class="col-4">
<img src ...>
</div>
<div class="col-4">
<img src ...>
</div>
<div class="col-4">
<img src ...>
</div>
</div>
</div>
您需要将引导程序添加到您的 HTML:
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
注意:本例中的 bootstrap 版本为 3.4.1
推荐阅读
- ember.js - setApplication 中断了 ember-qunit 测试上下文
- java - 验证后更改对象字段的值
- jakarta-mail - 如何使用 Java 从电子邮件正文中提取数据
- kendo-ui - 带有图标的 Kendo TreeView 远程数据
- node.js - 是否可以在使用节点 js 的 Web 技术中使用 Badge Api 推送通知?
- python - 当 G 来自 read_gexf 时如何修复 G.degree[0] 的 KeyError
- java - mvn 依赖项:resolve -Dclassifier=javadoc 在深层依赖项中的“无效模块名称”上失败。如何跳过这个问题?
- c++ - C++ 标识符未定义
- php - 想要访问网站上最新的 Instagram 订阅源,但没有收到来自 Instagram 的任何回复
- angular - 提供 Angular 组件使用的专用 api 访问时的热与冷 observables