html - bootstrap 4列的内容难以垂直居中
问题描述
我遇到的问题是,如果我将 my-auto 类应用于列 div,所有内容都按预期垂直居中,但 div 的背景图像也是如此。我尝试仅将内容包装在 div 中并应用 my-auto,将垂直居中的 css 类应用到仅针对元素的子元素或第一个子元素的列 div(通常会导致失去响应能力)。我不完全确定接下来要尝试什么,这有点令人沮丧。我尝试的一切要么将图像的顶部和底部与它的内容一起粉碎到列的中心。或者当屏幕尺寸变小时导致内容不再响应并从列中出来。
我的 HTML
<div class="col-sm-6 mail-bg text-black">
<h1>Subscribe to our Mailing List!</h1>
<p>Sign up and stay up to date with anything Any Given Room! By
signing up you will receive a 10% discount on our merch for life!
And if you get tired of us? Cancel your subscription at any time.
<p>
<span class="text-danger"
ng-show="subForm.subInput.$touched && subForm.subInput.$invalid"><b>Email
field cannot be empty.</b></span>
<form name="subForm">
<div class="form-group my-3">
<input type="text" name="subInput" class="form-control"
placeholder="Enter email" ng-model="mailForm.email" required>
</div>
<a class="w3-button w3-black w3-border my-3" type="submit"
ng-click="subscribe()">Subscribe</a>
</form>
</div>
我的 css 类添加了背景图像。(只是为了清楚起见)
.mail-bg {
background-image: url("./images/letter background.jpg");
background-repeat: no-repeat;
background-size: cover;
}
解决方案
推荐阅读
- html - 如何从 Bootstrap 5 折叠侧菜单中的链接拆分菜单 Chevron?
- heroku - Heroku 部署失败
- python - pandas lexsort 是否取决于排序顺序?
- asp.net-core - ASP.NET Core 5 的帮助程序库 - NuGet 包不可用?
- html - 如何使用 SCRIPT SRC 打开新标签页
- html - Onload 模式弹出窗口不起作用!当我单独运行它时它完全可以工作,但是当我将它附加到我的网站代码时它不起作用!为什么?
- flutter - 方法不可用:ext.flutter.inspector.setPubRootDirectories
- xaml - 如何更改弹出菜单中所选项目的颜色?
- mongodb - MongoDB和python使用Motor,对数据库的读写操作显示错误
- hibernate - SQL 查询以检索 addScalar 值的值