html - 将三个 div 并排对齐在一行中
问题描述
我希望在没有任何 flexbox 和网格的情况下并排对齐三个 div。
这是我正在寻找的风格:图片
这就是我目前得到的:图片
.container {
width: 600px;
border: 1px solid black;
}
.box-1 {
width: 180px;
height: 100px;
background: grey;
margin: 10px;
display: inline-block;
}
.box-2 {
width: 180px;
height: 100px;
background: grey;
margin: 10px;
display: inline-block;
}
.box-3 {
width: 180px;
height: 100px;
background: grey;
margin: 10px;
display: inline-block;
}
<div class="container">
<div class="box-1"></div>
<div class="box-2"></div>
<div class="box-3"></div>
</div>
注意:只是询问对齐,而不是边框,背景等
编辑:父容器的宽度为 600 像素。它不能改变。孩子们有 180 像素的宽度和 100 像素的高度,以及 10 像素的边距。
解决方案
嘿增加容器的宽度如下:
.container {
width: 1000px;
border: 1px solid black;
}
.box-1 {
width: 180px;
height: 100px;
background: grey;
margin: 10px;
display: inline-block;
}
.box-2 {
width: 180px;
height: 100px;
background: grey;
margin: 10px;
display: inline-block;
}
.box-3 {
width: 180px;
height: 100px;
background: grey;
margin: 10px;
display: inline-block;
}
<div class="container">
<div class="box-1"></div>
<div class="box-2"></div>
<div class="box-3"></div>
</div>
或display : flex
在您的容器中使用两者都会有所帮助....
推荐阅读
- json - Scala 对象、数据集和数据框之间的链接
- win2d - 使用 Win2D 是否可以在没有绘图会话的情况下获得文本大小?
- ios - 运行 ionic cordova build ios --prod 时出错
- python - 选择一个随机图像并为水印做 PIL
- python - 使用 Stripe 与 Angular 和 Django 创建新用户时,如何添加其他公司字段?
- c++ - C++/C:将字符串转换为初始化列表
- python - Python readlines() 返回空字符串
- python - i += x > 0 是什么意思?
- electron - 是否有相当于 ipcRender.invoke 的主进程?
- node.js - Axios 响应未正确执行