部分未显示在标题下

时间:2015-07-27 18:43:45

标签: html css

我一直试图解决我的问题几个小时,但它似乎不太清楚。我有一个标题图像和一个导航栏。我需要导航栏显示在标题图像下面,但它会一直显示在它上面。

CSS:

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  font-size: 100%;
  vertical-align: baseline;
}

html {
  line-height: 1;
}

ol, ul {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

caption, th, td {
  text-align: left;
  font-weight: normal;
  vertical-align: middle;
}

q, blockquote {
  quotes: none;
}
q:before, q:after, blockquote:before, blockquote:after {
  content: "";
  content: none;
}

a img {
  border: none;
}

article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary {
  display: block;
}

@font-face {
  font-family: Fragment;
  src: url("../fonts/Fragmentcore.otf");
}
.site-nav {
  position: absolute;
  left: 100px;
  outline: 1px solid;
  background: #fff;
  width: 12%;
  text-align: center;
  height: 100%;
}
.site-nav li {
  margin: 0.97em 0.8em 0 0.8em;
  border-bottom: 1px dotted;
  padding-top: 6px;
  padding-bottom: 6px;
}
.site-nav a {
  color: black;
  font-size: 1.25em;
  text-decoration: none;
  font-family: 'Fragment';
  font-weight: bold;
}
.site-nav li:hover {
  background: rgba(0, 0, 0, 0.8);
  border-bottom-color: #fff;
}
.site-nav li:hover a {
  color: #fff;
}
@media screen and (max-width: 768px) {
  .site-nav {
    left: 85px;
    width: 19%;
  }
}

header {
  position: absolute;
  height: 100%;
  width: 100%;
  background-size: cover;
}

.header-container {
  position: absolute;
  z-index: -1;
  background-color: white;
  background: url(../img/bg.jpg) no-repeat bottom center scroll;
  background-size: cover;
  width: 100%;
  height: 100%;
  /*@media screen and (min-width: $size-small){
      height: 100%;
      padding: 0;
  }*/
}

h1 {
  text-align: center;
  font-size: 1.7em;
  font-family: 'Fragment';
  font-weight: bold;
  margin-top: 45px;
  margin-bottom: 42px;
}

HTML:

<body>
    <header>
        <div class="header-container"></div>
    </header>

    <section id="content">
        <nav class="site-nav">
            <h1>Chronology</h1>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Photos</a></li>
                <li><a href="#">Art</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </section>
</body>

感谢任何帮助。谢谢:))

1 个答案:

答案 0 :(得分:0)

尝试将height: 100%添加到html, body,从position: absolute移除header并将top: 100%设置为.site-nav,如下所示:

&#13;
&#13;
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  font-size: 100%;
  vertical-align: baseline;
  box-sizing: border-box;
}

html {
  line-height: 1;
}

html, body{ /*added*/
    height: 100%;
}

ol, ul {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

caption, th, td {
  text-align: left;
  font-weight: normal;
  vertical-align: middle;
}

q, blockquote {
  quotes: none;
}
q:before, q:after, blockquote:before, blockquote:after {
  content: "";
  content: none;
}

a img {
  border: none;
}

article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary {
  display: block;
}

@font-face {
  font-family: Fragment;
  src: url("../fonts/Fragmentcore.otf");
}
.site-nav {
  position: absolute;
  left: 100px;
  border: 1px solid;
  background: #fff;
  width: 12%;
  text-align: center;
  top: 100%; /*added*/
    
}
.site-nav li {
  margin: 0.97em 0.8em 0 0.8em;
  border-bottom: 1px dotted;
  padding-top: 6px;
  padding-bottom: 6px;
}
.site-nav a {
  color: black;
  font-size: 1.25em;
  text-decoration: none;
  font-family: 'Fragment';
  font-weight: bold;
}
.site-nav li:hover {
  background: rgba(0, 0, 0, 0.8);
  border-bottom-color: #fff;
}
.site-nav li:hover a {
  color: #fff;
}
@media screen and (max-width: 768px) {
  .site-nav {
    left: 85px;
    width: 19%;
  }
}

header {
  /*position: absolute;*/ /*removed*/
  height: 100%;
  width: 100%;
  background-size: cover;
}

.header-container {
  position: absolute;
  z-index: -1;
  background-color: white;
  background: url(http://i.stack.imgur.com/gijdH.jpg?s=328&g=1) no-repeat bottom center scroll;
  background-size: cover;
  width: 100%;
  height: 100%;
  /*@media screen and (min-width: $size-small){
      height: 100%;
      padding: 0;
  }*/
}

h1 {
  text-align: center;
  font-size: 1.7em;
  font-family: 'Fragment';
  font-weight: bold;
  margin-top: 45px;
  margin-bottom: 42px;
}
&#13;
<header>
        <div class="header-container"></div>
    </header>

    <section id="content">
        <nav class="site-nav">
            <h1>Chronology</h1>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Photos</a></li>
                <li><a href="#">Art</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </section>
&#13;
&#13;
&#13;

无论如何更好地从position: absolute移除.site-nav并让它遵循文档的流程,我评论css中的更改。我真的推荐你这个:

&#13;
&#13;
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
  margin: 0;
  padding: 0;
  border: 0;
  font: inherit;
  font-size: 100%;
  vertical-align: baseline;
}

html {
  line-height: 1;
}

html, body{
    height: 100%;
}

ol, ul {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

caption, th, td {
  text-align: left;
  font-weight: normal;
  vertical-align: middle;
}

q, blockquote {
  quotes: none;
}
q:before, q:after, blockquote:before, blockquote:after {
  content: "";
  content: none;
}

a img {
  border: none;
}

article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary {
  display: block;
}

@font-face {
  font-family: Fragment;
  src: url("../fonts/Fragmentcore.otf");
}
.site-nav {
  /*position: absolute;*/  /*removed*/
  /*left: 100px;*/  /*removed*/
  /*width: 12%;*/
  display: inline-block; /*added*/
  margin-left: 100px;
  border: 1px solid;
  background: #fff;
  text-align: center;
  top: 100%; /*added*/
    
}
.site-nav li {
  margin: 0.97em 0.8em 0 0.8em;
  border-bottom: 1px dotted;
  padding-top: 6px;
  padding-bottom: 6px;
}
.site-nav a {
  color: black;
  font-size: 1.25em;
  text-decoration: none;
  font-family: 'Fragment';
  font-weight: bold;
}
.site-nav li:hover {
  background: rgba(0, 0, 0, 0.8);
  border-bottom-color: #fff;
}
.site-nav li:hover a {
  color: #fff;
}
@media screen and (max-width: 768px) {
  .site-nav {
    margin-left: 85px;
  }
}

header {
  /*position: absolute;*/ /*removed*/
  height: 100%;
  width: 100%;
  background-size: cover;
}

.header-container {
  position: absolute;
  z-index: -1;
  background-color: white;
  background: url(http://i.stack.imgur.com/gijdH.jpg?s=328&g=1) no-repeat bottom center scroll;
  background-size: cover;
  width: 100%;
  height: 100%;
  /*@media screen and (min-width: $size-small){
      height: 100%;
      padding: 0;
  }*/
}

h1 {
  text-align: center;
  font-size: 1.7em;
  font-family: 'Fragment';
  font-weight: bold;
  margin-top: 45px;
  margin-bottom: 42px;
  margin-top: 0;
}
&#13;
<header>
        <div class="header-container"></div>
    </header>

    <section id="content">
        <nav class="site-nav">
            <h1>Chronology</h1>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">Photos</a></li>
                <li><a href="#">Art</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </section>
&#13;
&#13;
&#13;