我正在创建一个页面,其中包含固定的导航栏,全屏背景和中间的文本。我不知道如何在横向模式下使其响应。在其他版本上,它的行为正常,但在横向上,因为我认为高度要小得多,所以文本与导航栏重叠。它看起来非常混乱。
我现在的代码中有什么东西可以改变来解决这个问题,但仍然保留全屏div吗?我到处都看,但没有什么工作。
到目前为止,这是我的代码:
.hero {
height: 100vh;
width: 100%;
background: url('http://lorempixel.com/1200/600/') no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: relative;
}
.headline {
position: absolute;
top: 50%;
left: 0%;
right: 0;
transform: translate(0%, -50%);
-webkit-transform: translate(0%, -50%);
}
.headline h2 {
font-weight: 100;
font-size: 48px;
color: #212121;
margin-bottom: 10px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="hero">
<nav class="navbar navbar-toggleable navbar-light bg-faded fixed-top">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<div class="headline text-center">
<div>
<h2>Lorem ipsum dolor sit amet, consectetur adipiscing elit. <br>Morbi in volutpat diam, ut laoreet magna. </h2>
<a class="btn btn-primary rounded-0" href="#">LINK ONE</a>
<a class="btn btn-secondary rounded-0" href="#" target="_blank">LINK TWO</a>
</div>
</div>
<!-- /.headline -->
</div>
<div style="height:900px"></div>
答案 0 :(得分:2)
您可以使用媒体查询
设置CSS对于Exp:
<style type="text/css">
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px)
and (orientation : landscape) {
/* STYLES GO HERE */
height: 50vh;
}
</style>