css - 如何使用图像作为 Bootstrap 的封面

标签 css twitter-bootstrap

我必须使用 Bootstrap 3 和 CSS 设计一个响应式网站。对于封面,我正在使用图像。它的尺寸是 4928 × 2747(可能太大了?)。

到目前为止,我是这样集成它的:

HTML:

<div class="jumbotron cover">
  <div class="container text-center">
    <hr border-top="3px">
    <h1 class="cover">Heading</h1>
    <a class="btn btn-cover" href="#" role="button">
      <span class="glyphicon glyphicon-play"></span>
      Check out the XX
    </a>
  </div> 
</div> 

CSS:

.jumbotron.cover {
  background-image: url('images/new/DSC_0750_cropped_blended.jpg');
  background-size: cover;
  background-repeat: no-repeat;
  height: 700px;
  margin-bottom: 0px;
}

考虑到响应式方面,我认为固定的 height: 700px; 不是一个选项。但是当我放下它时,图像会在底部被剪切。我认为 cover-div 现在的高度是由其中所有元素的高度之和定义的。

基本上我在问自己在尝试保持响应时在哪里以及如何定义 div 的高度?

最佳答案

您可以尝试下面的解决方案,或者您必须使用媒体查询:

<div class="jumbotron cover">
  <img src="images/new/DSC_0750_cropped_blended.jpg">
  <div class="container text-center">
    <hr border-top="3px">
    <h1 class="cover">Heading</h1>
    <a class="btn btn-cover" href="#" role="button">
      <span class="glyphicon glyphicon-play"></span>
      Check out the XX
    </a>
  </div>
</div>

<style>
  .jumbotron.cover {
    position: relative;
   }
  img {
    position: absolute;
    z-index: -1;
    width: 100%;
  }
</style>

关于css - 如何使用图像作为 Bootstrap 的封面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32378035/

相关文章:

CSS - float : right - div height is so tight

javascript - 将 javascript 显示为代码片段

html - CSS3 多个背景,一个在 ul 中重复

html - 我的 Bootstrap 模式显示正常,但背景不会褪色

javascript - 当此值更改时,如何确保 Bootstrap 列扩展以适应其内容的宽度?

css - 在 45 度旋转元素上应用 50% 后的透明度

html - 下拉菜单随着浏览器变小而改变宽度

javascript - Ace 编辑器无法与 bootstrap 配合使用

html - Bootstrap glyphicon 作为按钮显示在 table 上

css - 内容显示在超大屏幕电影中