html - 部分未显示在标题下

标签 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>

感谢任何帮助。谢谢:)

最佳答案

尝试将 height: 100% 添加到 html, body 中,从 header 中删除 position: absolute 并设置top: 100%.site-nav 像这样:

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;
}
<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>

无论如何最好从 .site-nav 中删除 position: absolute 并让它跟随文档的流程,我评论了 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;
}

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;
}
<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>

关于html - 部分未显示在标题下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31660861/

相关文章:

javascript - Canvas.toDataURL 不适用于移动 Safari iOS?

javascript - 如何将一个元素添加到另一个在 javascript 中动态创建的元素之上

javascript - Canvas 矩形填充颜色

css - 当容器和​​内容高度都未知时,如何将内容刷新到容器底部?

html - iPhone 6+ Mobile safari iOS 8 横向打开标签,Bootstrap navbar-fixed-top 在打开时不会关闭

html - CSS3 文本不会垂直对齐

javascript - ASP.NET 表单不提交

.net - 使用正则表达式查找不在 html 标记中的特定字符串

html - 如何使用 CSS 强制 TD 达到一定高度?

html - Wordpress 菜单项视频灯箱