【问题标题】:The Content section goes over top the header内容部分超出标题
【发布时间】:2013-11-16 03:20:02
【问题描述】:

我想做类似于http://www.thomaspomarelle.com/ 的东西(当然是定制设计),但我遇到的问题是我的 about 部分应该在背景图片下方并通过滚动页面访问,继续标题顶部:(而且我绝对不知道为什么。我在想那是因为我在正文中有图像,但我尝试将图像放在标题部分之后的 div 中,但它不起作用一点也不。 这是我的代码:

<html>
  <head>
    <title>yudasinal</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
    <link rel="stylesheet" type="text/css" href="custom.css">
   </head>

 <body id="backimage">
    <nav class="navbar-wrapper navbar-default navbar-fixed-top" role="navigation">
        <div class="container">
          <div class="navbar-header">
            <a class="navbar-brand" href="#">LOGO</a>
          </div>
          <div id = "projects">
            <ul>
              <li class = "line">
                <a href = "#">HOME</a>
              </li>
              <li class = "line">
                <a href = "#">HOME</a>
              </li>
              <li class = "line">
                <a href = "#">HOME</a>
              </li>
            </ul>
    </nav>  

    <script src="//code.jquery.com/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>

这是它的css:

#projects ul {
    text-align: right;
    margin-right: 10px;
    padding: 15px 15px;
    font-size: 18px;
    line-height: 60px;
}

#projects li {
    display: inline-block;
    height: 40px;
    position: relative;
    overflow: hidden;
    background-position: top center; 
}

#projects ul li.line a {
    padding: 0 30px 30px;
    text-align: center;
}

#projects li.line a::after {
    position: absolute;
    top: 87%;
    left: 0;
    width: 100%;
    height: 3px;
    background: black;
    content: '';
    opacity: 0;
    -webkit-transition: height 0.3s, opacity 0.3s, -webkit-transform 0.3s;
    -moz-transition: height 0.3s, opacity 0.3s, -moz-transform 0.3s;
    transition: height 0.3s, opacity 0.3s, transform 0.3s;
    -webkit-transform: translateY(-10px);
    -moz-transform: translateY(-10px);
    transform: translateY(-10px);
}

#projects li.line a:hover::after,
#projects li.line  a:focus::after {
    height: 5px;
    opacity: 1;
    -webkit-transform: translateY(0px);
    -moz-transform: translateY(0px);
    transform: translateY(0px);
}


#backimage {
    background-image: url(http://cs425729.vk.me/v425729136/4e67/6abwVXLTK9s.jpg);
    background-repeat: no-repeat;
    background-position: center center;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    width: 100%;
    height: auto;
}

.wrapper {
  width: 1000px;
  margin: auto;
  clear: both;
  z-index: 10;
}

它也有 twitter 引导 css。

非常感谢提前帮助!!!

【问题讨论】:

  • 什么是“关于部分”和什么是“标题部分”?我只能在正文中看到 nav 元素。并且有许多未闭合的标签使 DOM 变得一团糟。你应该换一个新的编辑器。

标签: html css twitter-bootstrap background background-image


【解决方案1】:

我一直在尝试获得同样的效果。我发现 html、body 和包含背景图像的 div 需要 100% 的高度。我发现这样做的最好方法。如果有人有更好的方法,请分享。

小提琴:http://jsfiddle.net/b87pV/

HTML

 <body>
 <div class="first">
     <div class="header">
         <div class="logo">LOGO</div>
         <nav>
             <ul>
               <li><a href="#">link</a></li> 
               <li><a href="#">link</a></li>
               <li><a href="#">link</a></li>
             </ul>   
         </nav>
      </div>
 </div>
 
<div class="second">
  <div id="projects">
  <h1>Projects</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi nesciunt explicabo ipsam laudantium quaerat dolorem molestiae. Reprehenderit, perspiciatis, assumenda, repellat dolores dolore corporis doloribus voluptatem magni suscipit aperiam fugiat quia.
    </p>    
</div>

CSS

 html,body {
        height: 100%;
        padding: 0;
        margin: 0;
    }    
    .first {
        height: 100%;
        background-image: url(http://cs425729.vk.me/v425729136/4e67/6abwVXLTK9s.jpg);
        background-repeat: no-repeat;
        background-position: top center;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
    .header {
        background: #333;
        height: 60px;
    }
    .logo, a {
        color: white;
    }
    .logo {
        float: left;
        padding: 20px;
    }
    nav {
        float: right;
        padding: 5px
    }
    nav li{
        display: inline-block;
        padding-right: 50px;
    }
    #projects {
        padding: 50px;
    }

我相信 Internet Explorer 会在 background:cover 上出现问题。那里有解决方法。简单搜索即可。

【讨论】:

  • 非常感谢您的帮助!有用! :) 虽然我仍然不确定为什么 div 或 body 的选项不起作用。
  • 很高兴我能帮上忙!我发现有时将事情简化为基本要素并从那里开始工作很有帮助。
  • 是的,你说得对,我觉得那里有很多不必要的代码 :) 现在是时候弄清楚其他事情了!
猜你喜欢
  • 2017-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 2016-11-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多