html - 带有弹性容器和显示背景图像的引导布局登录页面问题
问题描述
一段时间以来,我一直在为一些非常痛苦的问题而苦苦挣扎。
我正在尝试使用简单的布局创建登录页面:
在宽度超过 800 像素的屏幕上:
- 两列
- 在左侧,我想显示一个徽标、登录表单、文本框和按钮。没有背景图片。
- 在右侧,我想显示一个带有背景图像的 div。
在小于或等于 800 像素的屏幕上:
- 带有徽标、登录表单、文本框和按钮的单列。
- 大屏右栏显示的背景图,在小屏上应该显示为这一栏的背景图。
html文件
<div class="flex-container">
<div class="col-lg-4 index-top">
<div class="row">
<div class="col log-in">
<div class="col no-padding">
<h1>
<img src="/img/AnonimowySygnalista.svg" alt="logo Anonimowy Sygnalista" class="logo-login" />
<span class="sr-only hidden">Anonimowy sygnalista</span>
</h1>
<form action="">
<label for="">UserName</label>
<input type="" id="" name="" placeholder="Wpisz otrzymany login" class="input"></input>
<input type="submit" value="Zaloguj" class="btn-primary"></input>
</form>
</div>
</div>
</div>
</div>
<div class="col-lg-8 col background-img">
</div>
CSS 文件
.container {
display: block;
padding: 0;
margin: 0;
}
.flex-container {
display: flex;
flex-direction: column;
}
input, textarea {
display: block;
}
.right {
float: right;
}
.left {
float: left;
}
.clear {
clear: both;
}
label {
font-weight: 700;
margin-bottom: .75rem;
}
.btn-primary {
background-color: #1F7AAB;
border-radius: 4px;
border-color: #1F7AAB;
padding: .5rem 1.5rem;
width: 100%;
box-shadow: none;
color: #fff;
}
.background-img {
background-image: url('../img/pexels-vlada-karpovich-4050312.jpg');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
margin-top: -1.25rem;
}
.input {
margin-bottom: 1.5rem;
max-height: 5rem;
padding: .5rem .5rem .5rem .75rem;
border: 1px solid #767676;
box-sizing: border-box;
border-radius: 4px;
width: 100%;
}
.log-in h1 {
margin: 3rem 0;
}
.index-top {
z-index: 999;
}
@media (min-width: 801px) {
.container {
width: 100% !important;
}
.flex-container {
padding-right: 80px;
flex-direction: row;
}
.index-top {
margin: 0 80px;
}
解决方案
将元素堆叠在一起使用position : absolute
将其添加到.background-img
@media 内部应该会产生效果,您还需要z-index
css 属性来管理哪个元素在哪个元素后面
推荐阅读
- .net - .NET Core 调用 Encoding.GetEncoding() 挂起
- javascript - 为什么这个函数应该返回true时返回false?
- javascript - 尝试使用上下文 API 时“尝试分配给只读属性”
- c# - OpenXML和c#错误在sql server中插入数据表
- prestashop - Prestashop 管理员性能页面和信息页面说未找到
- google-maps-api-3 - 正常工作后 OVER_QUERY_LIMIT Google Maps API
- c# - 如何使用带有 3 个连接表的选择查询将数据加载到 DataGridView 和 TextBoxes 中?
- asp.net - 找不到方法:'无效 Microsoft.Reporting.WebForms.ReportViewer.Reset()'
- symfony - Symfony 将文件路径获取到树枝模板中,该文件位于 customBundle:Resources:views 中而不是 web dir
- c# - 发布请求 alidate 验证码 c#