html - 如何将包裹在弹性容器中的表单居中?
问题描述
.jumbotron {
background-image: url(background.jpg);
color: white;
text-align: center;
}
<div class="jumbotron">
<h1 class="display-4">My Awesome App</h1>
<p class="lead">This is why you should download this fantastic app!</p>
<p>Want to know more?</p>
<p>Join our mailing list!</p>
<hr>
<form class="form-inline" id="jumbo-form">
<div class="form-group mx-sm-3 mb-2">
<input type="password" class="form-control" id="email" placeholder="Email">
</div>
<button type="submit" class="btn btn-primary mb-2">Sign Up Now</button>
</form>
</div>
在 jumbotron 类中,表单之前的所有内容都居中。但是,表格左对齐。我尝试了其他问题的解决方案,例如添加绝对位置,然后添加边距:自动,但仍然无法正常工作。
解决方案
您的表单是一个 flex 容器,flex 可以水平居中
justify-content: center;
和垂直居中align-items: center
(如果高度足够可用)
在css下面添加,这将使表格居中
.form-inline {
justify-content: center;
}
推荐阅读
- c++ - C++ Fizzbuzz Leetcode 向量 push_back() 替换所有先前的元素
- sqlite - Flutter:为什么这个函数里面的方法没有访问数据库变量?
- java - 有没有办法找到安装在 OS X 上的 Java 版本的完整列表?
- java - 我应该在这个程序中传递什么参数以避免 java.lang 错误?
- r - 将另一列添加到数据框中,通过一个标签定义多个值的标签以绘制分组条形图
- python - 尽管成功登录,但用户身份验证失败
- html - CSS悬停在邻居上以切换属性
- python - scipy.optimize.curve_fit,参数全部返回 1
- java - 使用带有 Java 的 Tesseract 从图像中提取文本时出错
- oracle - 有什么方法可以在字典表中找到所有内置的 oracle 函数?