Bootstrap全高度背景封面图像

时间:2014-01-08 20:47:34

标签: image twitter-bootstrap height cover

我目前正在使用Bootstrap设计网站,并尝试在此网站上添加全高背景图片:http://lewisking.net/

这是我的代码:

HTML

<header class="title">

<div class="cut">
<img src="" height="">
</div>


<h2>Vintage Boutique Based in New York</h2>

<nav>
<ul>
<li><a href="#portfolio">SHOP</a></li>
<li><a href="#about">ABOUT</a></li>
<li><a href="#contact">PRESS</a></li>
</ul>
</nav>


</header>

CSS

header { 

  background: url(../img/nycfull.png) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

.cut img {
max-width: 100%;
height: auto;
max-height: 100%;
}

然而,我无法看到图像覆盖整个“首屏”部分。图像的高度与标题中的文本一样高。知道我做错了吗?

2 个答案:

答案 0 :(得分:12)

你的意思是demo吗?

如果是,请尝试以下代码:

CSS代码

.cover{
    color: rgb(255, 255, 255);
    position: relative;
    min-height: 350px;
    background: url("http://lewisking.net/images/header-image.jpg") no-repeat scroll 0px 100% / cover transparent;
}

nav ul li {
  list-style:none;
  float:left;
  margin-right:50px;

}

HTML CODE:

<div class="cover">
  <div class="clearfix"></div>
   <nav>
    <ul>
    <li><a href="#portfolio">SHOP</a></li>
    <li><a href="#about">ABOUT</a></li>
    <li><a href="#contact">PRESS</a></li>
    </ul>

  </nav>

</div>

答案 1 :(得分:0)

你的导航和标题不应该在一起!使用标题显示您网站的初始部分(人们在您的网页上看到的内容)。向导航中添加位置以将其修改到您想要的位置。

全高封面图片的CSS代码:

header {
background-image: url(background-img.jpg);
background-repeat: no-repeat;
background-attachment: scroll;
background-position: bottom;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
min-height: /*enter value here*/;
}

在您的HTML中,您应首先为<nav> navbar html here </nav>编码,然后为<header> header html here </header>编码。

如果您要将网站编码为可移动设备,请阅读本教程以实施有效的封面图片修复:CSS background-size: cover – Making it work for mobile / iOS

相关问题