html - 垂直堆叠 div 框的问题
问题描述
我有以下代码:
.blueleft {
background-color: white;
width: 300px;
border: 25px #cee2e8;
padding: 25px;
margin: 40px;
float: left;
font-family: "berlin sans fb";
color: gray;
font-size: 20px;
text-align: center;
vertical-align:middle;
}
.blueright{
background-color: white;
width: 300px;
border: 25px #cee2e8;
padding: 25px;
margin: 40px;
float: right;
font-family: "berlin sans fb";
color: gray;
font-size: 20px;
text-align: center;
vertical-align:middle;
}
但是我仍然让盒子元素像这样水平堆叠:
我不确定我需要做什么来确保 div 框垂直堆叠,并且在需要时仍然能够水平格式化和居中。我一直在环顾四周,但找不到可以放入 html 文档的代码....在 css 中格式化 DIV 元素时,我将如何从头开始?
解决方案
这是一个使用Flexbox的简单示例:
.flex-container {
display: flex;
flex-direction: column;
background-color: DodgerBlue;
height: 400px;
align-items: center;
justify-content: center;
}
.flex-container > div {
background-color: #f1f1f1;
width: 100px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
<div class="flex-container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
推荐阅读
- jenkins - 在 Jenkins 远程从站上运行 SonarQube Scanner
- python - 尝试从 SFTP 服务器流式传输文件时出现 Python Paramiko UTF-8 错误
- javascript - 有没有办法在多个文件中使用一个变量?
- r - 运行 KNN 时,“测试”和“训练”的亮度不同
- sql-server - 如何每天在 SQL Server 的视图中获取更新的表数据?
- spring - 访问自定义 logback appender 中的请求参数
- excel - 范围不适用于使用复选框条件中的自动过滤器的 Excel 表
- angular - Angular6 - 我如何测试是否应用了 [ngClass]?
- mysql - python manage.py migrate 在 windows 10 中使用 xamp (phpmyadmin) 和 Django 引发错误
- java - 如何将 subList 实现为 JSONArray