html - 如何并排创建 3 个大小相同的盒子?

标签 html css alignment

假设我有一个具有以下规范的容器:

 .container {
 width: 960px;
 margin: 0 auto;
 height: 500px;
 }

现在在中间,我想添加 3 个彼此水平对齐的框,规范如下:

 .box1 {
 background-color: #000;
 width: 300px;
 height: 200px;
 }
 .box2 {
 background-color: #999;
 width: 300px;
 height: 200px;
 }
 .box3 {
 background-color: #333;
 width: 300px;
 height: 200px;
 }

我尝试在每一个上都使用 margin-top 和 margin-left 但这很困惑而且让它们看起来同样对齐并且它们之间有足够的间距很麻烦。创建它的最佳方法是什么?

最佳答案

你必须输入“float:left;”在每个类(class)。

 .container {
 float:left;
 width: 960px;
 margin: 0 auto;
 height: 500px;
 }

.box1 {
 float:left;
 background-color: #000;
 width: 300px;
 height: 200px;
 }
 .box2 {
 float:left;
 background-color: #999;
 width: 300px;
 height: 200px;
 }
 .box3 {
 float:left;
 background-color: #333;
 width: 300px;
 height: 200px;
 }

关于html - 如何并排创建 3 个大小相同的盒子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15915149/

相关文章:

html - 如何将复选框和跨度与文本和谷歌 API 符号对齐?

javascript - 如何基于angularjs从网站上的url中删除index.html

html - 使父元素扩展以包含相对定位的子元素?

html - DIV - 页面的精确中心

html - 如何垂直对齐(对齐)多个元素

html - 如何在 mac osx 上的 sublime 中编辑 HTML.tmLanguage

html - 我想将一个 css 三 Angular 形定位为背景

jquery - 单击链接时如何选择和取消选择复选框

html - 右上角的日期导致页眉偏心

html - 如何将 iframe 水平居中?