我目前正在使用Bootstrap 3尝试创建网站。我希望顶部有一个标题,如本例所示。这些方框就是为了给你一个关于我的网格现在如何布局的例子。
用语言来说,我需要它:
col-md
左侧横幅下面。到目前为止,我一直在尝试使用网格布局,但它不起作用:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<header>
<div class="row" style="background: url(images/header.jpg) no-repeat; color:#fff; height:100px;">
<div class="col-lg-6" style="border-color: #F0F; border: dashed;">
<img src="images/empty.gif" height="100" border="0">
</div>
<div class="col-lg-6" style="border-color: #F0F; border: dotted;">
<div class="navbar navbar-default navbar-static-top">
<div class="navbar-inner">
<ul class="nav">
<li><a href="#">FB</a></li>
<li><a href="#">Tumblr</a></li>
<li><a href="#">Twitter</a></li>
<li><a href="#">You Tube</a></li>
</ul>
</div>
</div>
<div class="navbar navbar-default">
<div class="navbar-inner">
<ul class="nav">
<li class="active"><a href="#" id="link">Home</a></li>
<li><a href="#" id="link">About</a></li>
<li><a href="#" id="link">Characters</a></li>
<li><a href="#" id="link">Archive</a></li>
<li><a href="#" id="link">Gallery</a></li>
</ul>
</div>
</div>
</div>
</div>
</header>
&#13;
问题很多,但我遇到的主要问题是让两个导航栏在一列中堆叠,同时保持左侧空。响应时,两个导航栏应低于空白区域。除了其他问题,这就是我需要帮助的地方。
使用网格是最好的方法,还是有更好的方法?
当前状态(根据@Marc Barbeau的回答更改我的代码后): 请注意,两个导航栏不会下拉到横幅下方,并且底部导航栏不会移动到第一个导航栏下方。
我认为它应该以小视图显示 当然,菜单的其余部分和猫图片将在屏幕下方。
的index.html
<div class='header'>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div id="logo">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#" class="link">Home</a></li>
<li><a href="#" class="link">About</a></li>
<li><a href="#" class="link">Characters</a></li>
<li><a href="#" class="link">Archive</a></li>
<li><a href="#" class="link">Gallery</a></li>
</ul>
</div>
</nav>
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">FB</a></li>
<li><a href="#">Tumblr</a></li>
<li><a href="#">Twitter</a></li>
<li><a href="#">You Tube</a></li>
</ul>
</div>
</nav>
</div>
</div>
</div>
的style.css
.header{
background-image: url("../images/header.jpg");
background-repeat: no-repeat;
height: 100px;
}
@media(min-width: 300px){
.header .nav>li {
float: right !important;
}
}
#logo{
background-color: rgba(255,0,0,0);
height: 100px;
}
.header{
background-image: url("https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png");
background-repeat: no-repeat;
height: 100px;
}
@media(min-width: 300px){
.header .nav>li {
float: right !important;
}
}
#logo{
background-color: rgba(255,0,0,0);
height: 100px;
}
&#13;
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<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>
<!-- <link rel="stylesheet" type="text/css" href="custom.css"> -->
</head>
<body>
<div class='header'>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div id="logo">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#" class="link">Home</a></li>
<li><a href="#" class="link">About</a></li>
<li><a href="#" class="link">Characters</a></li>
<li><a href="#" class="link">Archive</a></li>
<li><a href="#" class="link">Gallery</a></li>
</ul>
</div>
</nav>
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">FB</a></li>
<li><a href="#">Tumblr</a></li>
<li><a href="#">Twitter</a></li>
<li><a href="#">You Tube</a></li>
</ul>
</div>
</nav>
</div>
</div>
</div>
</body>
&#13;
答案 0 :(得分:3)
custom.css
文件(确保在bootsrap css之后包含以覆盖样式)custom.css
覆盖)index.html
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<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>
</head>
<div class='header'>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div id="logo">
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="#" class="link">Home</a></li>
<li><a href="#" class="link">About</a></li>
<li><a href="#" class="link">Characters</a></li>
<li><a href="#" class="link">Archive</a></li>
<li><a href="#" class="link">Gallery</a></li>
</ul>
</div>
</nav>
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-right">
<li><a href="#">FB</a></li>
<li><a href="#">Tumblr</a></li>
<li><a href="#">Twitter</a></li>
<li><a href="#">You Tube</a></li>
</ul>
</div>
</nav>
</div>
</div>
</div>
<强> custom.css 强>
.header{
background-image: url("http://i.stack.imgur.com/v2UgD.jpg");
background-repeat: no-repeat;
height: 100px;
background-color: black;
background-size: 500px;
}
@media(min-width: 500px){
.header .nav>li {
float: right !important;
}
}
@media(max-width: 500px){
.header{
background-size: 100vw;
}
}
#logo{
background-color: rgba(255,0,0,0);
height: 100px;
}
#logo{
background-color: red;
position: absolute;
top: 10px;
left: 10px;
width: 200px;
height: 100px;
background-image: url("images/header.jpg");
}
添加了几行额外的CSS以缩小500px下的背景徽标图像。