阻止容器div覆盖Bootstrap中的绝对相对div

时间:2017-10-03 22:31:08

标签: html css twitter-bootstrap css-position

site-header设置为relative时,引导程序container div会向上移动到站点标题空间,如下所示:

enter image description here

如何让标题看起来像这样?

enter image description here

Reference

   

.site-header {
    padding-left: 77.2px;
    padding-right: 77.2px;
    width: 100%;
    display: table;
}

.headerImage {
    height: 483px;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.headerText {
    padding: 6% 4%;
    width: 60%;
    position: relative;
    left: 40%;
    display: table-cell;
    vertical-align: middle;
    z-index: 2;
}

.row.standardPageContent {
  margin-top: 250px;
}
  

 <header class="site-header">
               <img class="headerImage" src="images/cornellCoverImageWetLab.png">
                <div class="headerText">
                    <div class="title">Wet Lab</div>
                    <div class="subtitle">We did some cool stuff and wrote this tagline</div>
                </div>
        </header>

    <!-- Sidebar -->
    <div id="sidebar" class="container">
        <div class="row standardPageContent">
            <div class="col-md-3 col-xs-3 sidebar">
        <ul>
            <li><a href="#overview">OVERVIEW</a></li>
            <li><a href="#biobricks">BIOBRICKS</a></li>
            <li><a href="#chassis">CHASSIS</a></li>
            <li><a href="#results">RESULTS</a></li>
            <li><a href="#futurework">FUTURE WORK</a></li>
            <li><a href="#references">REFERENCES</a></li>
        </ul>
        </div>

    <!-- Page Content -->
        <div class="col-md-9 col-xs-9 content">

                 <h1><a id="overview">Overview</a></h1>
                    <p>Paragraph writings will go here
                    </p>
                 <h1><a id="biobricks">Biobricks</a></h1>
                 <h1><a id="chassis">Chassis</a></h1>
                 <h1><a id="results">Results</a></h1>
                 <h1><a id="futurework">Future Work</a></h1>
                 <h1><a id="references">References</a></h1>

           </div>
</div>

1 个答案:

答案 0 :(得分:0)

如果您可以提供该页面的完整代码(至少是标题和概述容器行),我会给您解决方案。

请查看这个概念,以实现您的目标结构。

*,
 :after,
 :before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

.site-header {
  width: 100%;
  position: relative;
  background: orange;
  display: table;
}

.site-header .headerImage {
  width: 50%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

.site-header .headerText {
  background: rgba(213, 123, 75, 0.6);
  padding: 10% 10% 10% 40%;
  display: table-cell;
  vertical-align: middle;
  position: relative;
  z-index: 2;
}

.site-header .headerText .inner {
  background: #ccc;
  padding: 30px 50px;
}

.site-header .headerText .inner .title {
  font-size: 30px;
}

.overview-container-with-sidebar {
  width: 100%;
  position: relative;
  background: brown;
  float: left;
}

.sidebar {
  width: 30%;
  display: inline-block;
  float: left;
}

.overview-container {
  width: 70%;
  display: inline-block;
  float: left;
}
<header class="site-header">
  <img class="headerImage" src="http://via.placeholder.com/990x250">
  <div class="headerText">
    <div class="inner">
      <div class="title">Wet Lab</div>
      <div class="subtitle">We did some cool stuff and wrote this tagline</div>
    </div>
  </div>
</header>
<section class="overview-container-with-sidebar">
  <div class="sidebar">
    <ul>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
      <li>Links</li>
    </ul>
  </div>
  <div class="overview-container">
    <h2>Overview</h2>
    <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia
      voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi
      tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui
      in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
    <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia
      voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi
      tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui
      in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
  </div>
</section>