html - 如何使列水平或垂直对齐取决于 Bootstrap 4 中的视口?
问题描述
我有以下设置 -
.left {
height: 100vh;
background-color: #208ea3;
}
.right {
height: 100vh;
background-color: #37a862;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid" color="green">
<div class="row justify-content-md-start">
<div class="col-lg-3 left d-flex align-items-center justify-content-center" id="first-section">
<div class="text-center">
<div class="row-fluid align-items-center justify-content-center h-100">
<div class="col-xl-6" id="dynamic-columns">
some quotations
</div>
<div class="col-xl-6" id="dynamic-columns">
<h3>title</h3>
Some text
</div>
</div>
</div>
</div>
<div class="col-lg-9 right" id="next-section">
more text
</div>
</div>
</div>
我想将属性分配给#dynamic-columns
这样,当屏幕的 amax-height
为 500px 时,列占据 100% 的高度并并排排列。到目前为止,这种水平对齐不会发生,如果有更多文本,底部#dynamic-columns
会被隐藏。#next-section
我的要求来自这样一个事实,即许多手机在横向模式下的高度约为 500 像素,这不允许我#first-section
垂直显示内容。因此,我希望将它们水平对齐,以便第一个#dynamic-columns
在屏幕左侧,第二个在右侧。
我认为以下查询将是必要的,但我无法找到属性 -
@include (max-height:500px) {
#dynamic-columns {
display: ??
}
}
解决方案
您可以尝试如下。我将引导程序版本更新为 4.5 以便能够使用vh-100
.left {
background-color: #208ea3;
}
.right {
background-color: #37a862;
}
@media (max-height:500px) {
.left > div {
height:100%;
width:50%;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid" color="green">
<div class="row">
<div class="col-lg-3 vh-100 left d-flex flex-column flex-wrap justify-content-center text-center" id="first-section">
<div class="d-flex flex-column justify-content-center">
some quotations
</div>
<div class="d-flex flex-column justify-content-center">
<h3>title</h3>
Some text
</div>
</div>
<div class="col-lg-9 vh-100 right" id="next-section">
more text
</div>
</div>
</div>
推荐阅读
- sql - 如何在 BigQuery 中将此旧版 SQL 转换为标准 SQL?
- android - 设置过滤器结果后,Recyclerview 不显示任何项目
- arduino - Arduino 自定义霓虹灯控制灯光效果
- mongodb - MongoDB 从 3.6 升级到 4.0 后启动超时
- javascript - jQuery UI 在 Windows 智能板上不起作用
- gulp - Gulp Watch 不适用于 Linux 2 (WSL 2) 的 Windows 子系统
- pandas - 具有“主”和浮点数到非浮点数的对象列
- oracle - 如何在 oracle 上选择性地更新数据?
- github-actions - 推送新标签时如何不执行 GitHub 操作?
- reactjs - 如何在字典内的列表内的字典中添加一组键+值