Samuel Ferreira Samuel Ferreira - 4 days ago 4
CSS Question

Bootstrap website jumbotron image scaling

I'm new to bootstrap and HTML & CSS.
I was trying to use jumbotron on this website I'm trying to create but when I applied the background image I wanted it to fix a size even if the size of the window changed, in fact I wanted to do it on all of the website.

This is how the image is when full sized, and how I want it to be no matter the windows size
This is how the image is when full sized, and how I want to be no matter the windows size

This is the image when I reduce the size of the window

This is the image when I reduce the size of the window

And another thing somehow I got a bot and right margin on the website, I wanted to remove it, but I couldn't find from where it was coming .

Here's my HTML:

<!DOCKTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>WebHosting</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<!--NavBar-->
<div class="row">
<div class="col-lg-8">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<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="index.html">WebHosting</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="contactos.html">Contactos</a></li>
<li><a href="preços.html">Preços</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
</div>
</div><!--NavBar END-->
<!--<div class="row">
<div class="col-xs-12 col-sm-6 col-md-8"></div>
<div class="col-xs-6 col-md-4"></div>
</div>-->
<section class="jumbotron">
<div class="container">
<div class="row text-center">
<h1>WebHosting</h1>
<p>Host your WebSite now!!</p>
<p><a class="btn btn-primary btn-lg" href="precos" role="button">Learn more</a></p>
</div>
</div>
</section>
<!--<div class="row">
<div class="col-md-6">

</div>
<div class="col-md-6">

</div>
</div>-->
</body>
</html>


And CSS:

body {
}
.jumbotron{
align-items:center;
display:flex;
background-image:url('https://static.pexels.com/photos/392018/pexels-photo-392018.jpeg');
background-size:cover;
background-color:#898888;
height:500px;
color:white;
}

Answer

You can use viewport units to get it.

body {
   margin:0;
   padding:0;
}

.jumbotron {
  align-items: center;
  display: flex;
  background-image: url('https://static.pexels.com/photos/392018/pexels-photo-392018.jpeg');
  background-size: cover;
  background-color: #898888;
  height: 100vh; /* Add this */
  color: white;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <title>WebHosting</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  <link rel="stylesheet" href="main.css" type="text/css">
</head>

<body>
  <!--NavBar-->
  <div class="row">
    <div class="col-lg-8">
      <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container-fluid">
          <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                                <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="index.html">WebHosting</a>
          </div>
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
              <li><a href="contactos.html">Contactos</a></li>
              <li><a href="preços.html">Preços</a></li>
            </ul>
          </div>
          <!-- /.navbar-collapse -->
        </div>
        <!-- /.container-fluid -->
      </nav>
    </div>
  </div>
  <!--NavBar END-->
  <!--<div class="row">
            <div class="col-xs-12 col-sm-6 col-md-8"></div>
            <div class="col-xs-6 col-md-4"></div>
        </div>-->
  <section class="jumbotron">
    <div class="container">
      <div class="row text-center">
        <h1>WebHosting</h1>
        <p>Host your WebSite now!!</p>
        <p><a class="btn btn-primary btn-lg" href="precos" role="button">Learn more</a></p>
      </div>
    </div>
  </section>
  <!--<div class="row">
            <div class="col-md-6">

            </div>
            <div class="col-md-6">

            </div>
        </div>-->
</body>

</html>