css - 如何为css水平对齐两个容器?
问题描述
我是 CSS 的初学者。我尝试使用显示块,但它不起作用。这不仅仅是一个中心,因为也显示了许多容器。我尝试使用margin-bottom & right,但它也不起作用,变得像一个交叉的,几乎是平行的。
我正在尝试对齐第四个和五个 div。黑色和红色的一个。如果您尝试查看我的代码,我将不胜感激,在此先感谢您。
div#first {
background-color: #FF0000;
height: 180px;
width: 180px;
float: left;
position: relative;
}
div#third {
background-color: blue;
height: 180px;
width: 190px;
float: left;
margin-left: 190px;
position: relative;
}
div#fourth {
display: block;
background-color: black;
height: 100px;
width: 100px;
margin-left: 5px;
float: left;
}
div#five {
background-color: red;
height: 100px;
width: 100px;
float: left;
}
div#six {
background-color: navy;
height: 100px;
width: 100px;
float: left;
margin-left: 400px;
}
div#hello1 {
background-color: navy;
width: 80px;
height: 100px;
position: absolute;
bottom: 90px;
}
div#hello2 {
background-color: orange;
width: 200px;
height: 100px;
bottom: 90px;
margin-left: 85px;
position: absolute;
}
div#hello3 {
background-color: red;
width: 130px;
height: 100px;
position: absolute;
bottom: 90px;
margin-left: 290px;
}
div#hello4 {
background-color: navy;
width: 150px;
height: 100px;
position: absolute;
bottom: 90px;
margin-left: 425px;
}
<div class="content" id="first"> </div>
<div class="content" id="third"> </div>
<div class="content" id="fourth"> </div>
<div class="content" id="five"> </div>
<div class="content" id="six"> </div>
<div class="content" id="hello1"> </div>
<div class="content" id="hello2"> </div>
<div class="content" id="hello3"> </div>
<div class="content" id="hello4"> </div>
解决方案
我不认为我完全明白你的意思,但看看这个片段并告诉我这是否是你正在寻找的(打开
div#first{
background-color: #FF0000;
height: 180px;
width: 180px;
float: left;
}
div#third{
background-color: blue;
height: 180px;
width: 190px;
float: left;
}
div#fourth{
background-color: black;
height: 100px;
width: 100px;
float: left;
}
div#five{
background-color: red;
height: 100px;
width: 100px;
float: left;
}
div#six{
background-color: navy;
height: 100px;
width: 100px;
float: left;
}
div#hello1{
background-color: navy;
width: 80px;
height: 100px;
position: absolute;
bottom:90px;
}
div#hello2{
background-color: orange;
width: 200px;
height: 100px;
bottom:90px;
margin-left: 85px;
position: absolute;
}
div#hello3{
background-color: red;
width: 130px;
height: 100px;
position: absolute;
bottom:90px;
margin-left: 290px;
}
div#hello4{
background-color: navy;
width: 150px;
height: 100px;
position: absolute;
bottom:90px;
margin-left: 425px;
}
#aligned {
display : flex;
flex-direction: column;
}
<body>
<div class = "content" id = "first"> </div>
<div class = "content" id = "third"> </div>
<div id="aligned">
<div class = "content" id = "fourth"> </div>
<div class = "content" id = "five"> </div>
</div>
<div class = "content" id = "six"> </div>
</body>
推荐阅读
- c# - 当 DataGrid 行选择为空白时,ComboBox 输入字符串格式异常
- android - 在firestore android中删除项目后如何在recyclerview中删除项目
- android - 当 dao 设置为返回 Single 时找不到符号返回 RxRoom.createSingle
- >
- python - python中的requests.get(url)在循环中使用时表现不同
- javascript - 从 API React JS 获取数据时如何防止表格循环
- excel - 循环直到非空白列
- nix - Nix:如何用全局覆盖覆盖 stdenv.cc?
- javascript - Javascript document.write函数中是否有引号“和'的替代品
- angular - 在每一步使用 ngFor 的迭代根据索引
- reactjs - 受保护的路由在 API 响应到达之前重定向