简体   繁体   中英

Bootstrap Jumbotron Background Image

Have been searching this site up and down for hours, and cannot figure out what is wrong with making a jumbotron background image responsive (I am brand new to bootstrap). I have tried all of the below and nothing works. The image when resized will be extremely stretched out, cut off on the bottom or top, or get squeezed. I tried contain as well but that makes the image too small.

.jumbotron {
   height:600px;
   background: url("JoelCanada.jpg") no-repeat center center;
   -webkit-background-size: 100% 100%;
   -moz-background-size: 100% 100%;
   -o-background-size: 100% 100%;
   background-size: 100% 100%;
  } 
.jumbotron {
   height:600px;
   background: url("JoelCanada.jpg") no-repeat center center;
   -webkit-background-size: cover;
   -moz-background-size: cover;
   -o-background-size: cover;
   background-size: cover;
} 

And here is the HTML

   <div class="jumbotron jumbotron-fluid">
    <div class="container jumboText">


              <h2> Discover </h2>
 <p> Text </p>
   <button type="submit" name="countries" class="jumboButton"> Button &#8696 </button>
   <button type="submit" name="countries" class="jumboButton"> Button &#8696 </button>
    <button type="submit" name="countries" class="jumboButton"> Button &#8696 </button>
              </div>
      </div>

Any help appreciated

Not sure if it was intentional but you should only style the .jumbotron class once.

Your extra class jumboText uses camelcase which does not match current bootstrap class convention using the hyphen - . Style your header tags globally for consistency and use them in the HTML in a hierarchy with them starting with one h1 one a page at the top then cascading down as needed. Try use the built-in classes as much as possible and minimize on the custom classes and use them with reason.

Understanding this is also a bit unrelated but should be notated since your new to boostrap but your <button> 's should be a nchor tags using the bootstrap btn built in class system and style them globally in your CSS.

Below is a FIDDLE with the a "responsive" jumbotron background: https://jsfiddle.net/jeremykenedy/p1u3aryv/10/

You may want to reference this often until you are more familiar with the framework:

http://getbootstrap.com/css/ http://getbootstrap.com/components/ http://getbootstrap.com/javascript/

What the FIDDLE Shows:

HTML:

<nav class="navbar navbar-inverse navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Project name</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <form class="navbar-form navbar-right">
        <div class="form-group">
          <input type="text" placeholder="Email" class="form-control">
        </div>
        <div class="form-group">
          <input type="password" placeholder="Password" class="form-control">
        </div>
        <button type="submit" class="btn btn-success">Sign in</button>
      </form>
    </div>
    <!--/.navbar-collapse -->
  </div>
</nav>

<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
  <div class="container">
    <h1>Hello, world!</h1>
    <p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
    <p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more &raquo;</a></p>
  </div>
</div>

<div class="container">
  <!-- Example row of columns -->
  <div class="row">
    <div class="col-md-4">
      <h2>Heading</h2>
      <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
      <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
    </div>
    <div class="col-md-4">
      <h2>Heading</h2>
      <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
      <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
    </div>
    <div class="col-md-4">
      <h2>Heading</h2>
      <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
      <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
    </div>
  </div>

  <hr>

  <footer>
    <p>&copy; 2016 Company, Inc.</p>
  </footer>
</div>
<!-- /container -->

CSS:

.jumbotron {
  background: url(https://s3-us-west-2.amazonaws.com/consultjeremy.com/backgrounds/about-bg.jpg) no-repeat center center;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  min-height: 600px;
  color: #ffffff;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM