问题在于,在移动设备中,当我单击面包屑时,标题文本和按钮向下移到外面,使它位于标题图像之外。 是否可以将按钮和文本保持静态,而不必将导航移到标题的外部。 如果nav在标题之外,则不会发生。 https://jsfiddle.net/f4cejopu/
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<style type="text/css">
.row {
margin-right: 0px;
margin-left: 0px;
}
.navbar-custom {
background: transparent; !important;
z-index: 9999;
}
header {
background-image: url("https://i.imgur.com/w8jxzG4.jpg");
height: 80vh;
background-size: cover;
background-position: center;
background-attachment: fixed;
position: absolute;
width: 100%;
top: 0;
}
.navbar-custom {
background: transparent !important;
}
header h1{
color: #fff;
}
.header-content{
padding-top: 14rem;
padding-bottom: 10rem;
}
</style>
<title></title>
</head>
<body>
<header>
<nav class="navbar navbar-custom navbar-expand-sm navbar-dark bg-dark">
<a class="navbar-brand" href="#">Space</a>
<button class="navbar-toggler" 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>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Explore</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Shop
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<ul class="navbar-nav ml-auto"> <!-- margin-right auto -->
<li>
<a class="nav-link" href="#">Login</a>
</li>
<li>
<a class="nav-link" href="#">Register</a>
</li>
</ul>
</div>
</nav>
<div class="header-content">
<div class="row">
<div class="col-sm-10 mx-auto">
<h1>Welcome To The Space</h1>
</div>
</div>
<div class="row">
<div class="col-sm-10 mx-auto">
<button class="btn">Register for a trip</button>
</div>
</div>
</div>
</header>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
答案 0 :(得分:0)
防止nav
文本按下content
的最简单方法是通过定位将其从DOM流中删除。
.navbar.navbar-custom {
position: absolute;
left: 0;
right: 0;
}
您会发现您的内容将上移(因为navbar
不再影响其周围的元素-类似于将其从<header>
中删除)。此处的简单解决方法是将偏移量应用于内容。像这样:
.header-content {
margin-top: 3.4375rem // or ~55px
}
或者利用现有的padding-top
,例如:
.header-content {
padding-top: calc(3.4375rem + 4rem);
}
JSFiddle:https://jsfiddle.net/wmtsgxe4/