我正在试图弄清楚如何让我的导航位于jumobtron的顶部,但仍然受限于拥有容器类。另外我的h1和我想让我的标题内的h1和p也在容器内,但我希望jumbotron在页面的宽度上是完整的。我没有自己的任何风格,都来自bootstrap。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Me - Web Designer/Developer</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<header class="jumbotron">
<nav class="navbar navbar-default navbar-fixed-top">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#works">Works</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
<h1>Me</h1><p class="lead">Web Developer</p>
</header>
<div class="container">
<section id="services">
<h2 class="text-center">Services</h2>
<div class="row">
....
答案 0 :(得分:1)
Jumbotron和Navbars是不同的东西,不应该把它们放在另一个里面。当您将导航类定义为 navbar-fixed-top 时,您的导航将从页面的正常流程中删除,因此您需要这样的内容:
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a></li>
<li><a href="#services">Services</a></li>
<li><a href="#works">Works</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
</nav>
<header class="jumbotron">
<div class="container">
<h1>Me</h1>
<p class="lead">Web Developer</p>
</div>
</header>
我相信这应该足以满足您的需求。请告诉我们是不是。
答案 1 :(得分:1)
这是一个基本的例子。将导航栏更改为background: transparent
,将container
放在jumbotron
内以及navbar
内。
<header class="jumbotron">
<div class="container">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
工作示例:
nav.navbar {
background: transparent;
border: 0;
}
@media (max-width: 767px) {
nav.navbar .navbar-collapse {
border: 0;
box-shadow: none;
}
}
header {
background-image: url('http://www.100resilientcities.org/page/-/100rc/img/cities/cities-la_optimized.jpg');
background-size: cover;
background-position: center;
height: 400px;
}
header.jumbotron h1 {
padding-top: 100px;
}
header.jumbotron h1,
header.jumbotron p {
color: white;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<header class="jumbotron">
<div class="container">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Home</a>
</li>
<li><a href="#services">Services</a>
</li>
<li><a href="#works">Works</a>
</li>
<li><a href="#about">About</a>
</li>
<li><a href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</nav>
<h1>Me</h1>
<p class="lead">Web Developer</p>
</div>
</header>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>