我是bootstrap的初学者,我一直在尝试为我的网站创建一个主页。我面临的问题是:
三张图片与jumbotron重叠,我无法弄清楚原因。以下是HTML代码:
<!--navigation bar-->
<div class="navbar-wrapper">
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<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="logo" href="#"><img src="C:\Users\Mickey.Utopia\Documents\EdHoc\temp-logo.jpg" height= "50" width = "80"></a>
</div>
<div class="navbar-collapse collapse navbar-right">
<ul class="nav navbar-nav">
<!--
<li class="active"><a href="#">Home</a></li>
-->
<li class = "animate"><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href = "C:\Users\Mickey.Utopia\Documents\EdHoc\Sign_in.htm">Sign In</a></li>
<li><a href = "#">Sign Up</a></li>
</ul>
</div>
</div>
</nav>
</div>
<div class='jumbotron' >
<div class="container">
<div class="row">
<div class="col-xs-12 col-lg-12 col-sm-12" >
<h1 id="jumb">Welcome to EdHoc. <br>Discover the best places to learn and collaborate with friends to make learning easier.</h1>
</div>
<div class="row">
<div class="col-xs-8 col-lg-8 col-sm-8" id="search">
<!--Search Bar here-->
<input type="text" class="form-control" placeholder="Search by location, institute, discipline" id="srcb">
<!--Button-->
</div>
<div class="col-xs-4 col-lg-4 col-sm-4" id="button">
<a href="" class="btn btn-default">Go</a>
</div>
</div>
</div>
</div>
</div>
<hr>
<div class="container marketing">
<!-- Three columns of text below the jumbotron -->
<div class="row">
<div class="col-sm-8 col-xs-12 col-lg-4">
<img class="img-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
<h2>Heading</h2>
<p>Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna.</p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div><!-- /.col-lg-4 -->
<div class="col-lg-4">
<img class="img-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
<h2>Heading</h2>
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.</p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div><!-- /.col-lg-4 -->
<div class="col-lg-4">
<img class="img-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Generic placeholder image" width="140" height="140">
<h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<p><a class="btn btn-default" href="#" role="button">View details »</a></p>
</div><!-- /.col-lg-4 -->
</div><!-- /.row -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="\bootstrap-3.3.5-dist\bootstrap-3.3.5-dist\js\bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
相关的CSS(除了引导程序文件):
.navbar {
background-color: transparent;
border: none;
}
.jumbotron {
height: 400px;
background-image: url(../images/woman.jpg);
background-size: cover;
border: none;
width: 100%;
position: absolute;
top:0;
z-index: -100;
}
#jumb {
color: white;
font-size: 20px;
}
我该如何解决这个问题?
答案 0 :(得分:1)
你的jumbotron
div使用position:absolute,这就是为什么它下面的内容重叠的原因。请参阅以下参考资料:
position:absolute; 位置为绝对的元素;定位 相对于最近的定位祖先(而不是定位 相对于视口,像固定的那样。)
然而;如果绝对定位元素没有定位 祖先,它使用文档正文,并与页面一起移动 滚动。
注意:“定位”元素的位置是除了之外的任何元素 静态的。
和
重叠元素 当元素定位时,它们可以重叠 其他元素。
z-index属性指定元素的堆栈顺序( 元素应放在其他元素的前面或后面。)
元素可以具有正或负堆栈顺序:
Absolute, Relative, Fixed Positioning: How Do They Differ?
*您还有一些结构不一致,例如col-sm-8 col-xs-12 col-lg-4
将最小断点大小放在较大的大小之间没有意义:请参阅Grid
您应该首先查阅文档,了解这些组件的结构以及它们如何相互作用。 Docs
.navbar.navbar-custom {
background: none;
border: none;
margin-bottom: -50px;
}
div.jumbotron {
height: 400px;
background-image: url(http://interiorofficesystems.com/wp-content/themes/ios/uploads/product_photo/afe3a3ed124cb421preview%20-%20114371%20-%20Tayco_View02.jpg);
background-size: cover;
border: none;
}
div.jumbotron .jumb {
margin-bottom: 20px;
color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-static-top navbar-custom">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <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="logo" href="#">
<img src="http://placehold.it/80x50/266080/fff" height="50" width="80">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<ul class="nav navbar-nav navbar-right">
<li class="animate"><a href="#about">About</a>
</li>
<li><a href="#contact">Contact</a>
</li>
<li><a href="C:\Users\Mickey.Utopia\Documents\EdHoc\Sign_in.htm">Sign In</a>
</li>
<li><a href="#">Sign Up</a>
</li>
</ul>
</div>
</div>
</nav>
<div class='jumbotron'>
<div class="container">
<div class="jumb">
<h1>Welcome to EdHoc.</h1>
<br>
<p>Discover the best places to learn and collaborate with friends to make learning easier.</p>
</div>
<div class="input-group input-group-lg">
<input type="text" id="search" class="form-control" placeholder="Search by location, institute, discipline" id="srcb"> <span class="input-group-btn">
<button class="btn btn-default btn-lg" id="button" type="button">Go!</button>
</span>
</div>
</div>
</div>
<div class="container text-center">
<div class="row">
<div class="col-sm-4">
<img class="img-circle" src="http://placehold.it/200x200/000" alt="Generic placeholder image" width="140" height="140">
<h2>Heading</h2>
<p>Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna.</p> <a class="btn btn-default"
href="#" role="button">View details »</a>
</div>
<div class="col-sm-4">
<img class="img-circle" src="http://placehold.it/200x200/000" alt="Generic placeholder image" width="140" height="140">
<h2>Heading</h2>
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.</p> <a class="btn btn-default"
href="#" role="button">View details »</a>
</div>
<div class="col-sm-4">
<img class="img-circle" src="http://placehold.it/200x200/000" alt="Generic placeholder image" width="140" height="140">
<h2>Heading</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
<a
class="btn btn-default" href="#" role="button">View details »</a>
</div>
</div>
</div>