Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap container-fluid isn't the whole width of the screen

I'm doing a site and I'm starting with the mobile stylesheet first. But the container-fluid's width isn't the same as the window's width.

What I tried to do to fix this was:

 .container-fluid{
      width: 105%
 }

The problem now is that when I make the window a little smaller, it's still not enough, but when I make the window a little bit bigger, it's TOO MUCH, when I do that a scroll bar appears at the bottom.

100% doesn't work since I already said that it's not the full width of the window.

Here's the entire body from the HTML file:

<body>
<!-- Introduction -->

<div id="introduction" class="container-fluid">
    <div class="row">
        <header>
            <h1> Mosescu Bogdan Gabriel </h1>
            <img id="profilepic" src="profilepic.png" />
            <h2> Web Designer | Motion Graphics Artist </h2>
        </header>
    </div>
</div>
<!-- //Introduction// -->

<div id="about" class="container-fluid">
    <div class="row">
        <h1 id="about-title"> Who I am </h1>
    </div>
</div>
</body>

and this is the CSS file:

/*Introduction CSS */
#introduction{
background-color: #542437;
color: white;
margin-top: -21px;
}
#introduction header{
text-align: center;
}
#introduction header h1{
font-family: montserrat;
font-weight: bold;
}
#introduction header h2{
font-family: montserrat;
font-weight: normal;
font-size: 1em;
}
#profilepic{
border-radius: 100%;
width: 150px;
height: 150px;
}
/* //Introduction CSS// */


/* About CSS */
#about{
background-color: #f2f2f2;
color: #1a1a1a;
text-align: center;
margin-top: -24px;
}
#about-title{
font-family: montserrat;
font-weight: bold;
font-size: 2.25em;
border-bottom: solid 1px black;
}
like image 706
Blaze26 Avatar asked Aug 27 '16 13:08

Blaze26


1 Answers

Bootstrap containers are padded.

 .container-fluid {
    padding-right:15px;
    padding-left:15px;
    margin-right:auto;
    margin-left:auto
 }

You need to remove the padding.

.container-fluid {
    padding-right:0;
    padding-left:0;
    margin-right:auto;
    margin-left:auto
 }

Edit: This is a bare bones example. If you copy this and paste into a new .html document you'll see no padding on the container. If you then remove the container-fluid override you'll see padding.

<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title></title>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    
        <!-- put your override styles here - AFTER you include Bootstrap -->
        <link href="style-mobile.css" rel="stylesheet">

    </head>
    <style>
        /* override Bootstrap's container */
        .container-fluid {
            padding-right:0;
            padding-left:0;
            margin-right:auto;
            margin-left:auto
         }
    </style>
    <body>
    
        <div class="container-fluid">
            This text hits the left side of the viewport.
        </div>
    
    </body>
</html>

Edited HTML example to include new css link

Edit: Bootstrap 4

@Dagrooms commented: "The best way to do this in Bootstrap 4 is to add px-0 to your container-fluid div."

This will remove the padding from the left and right of the container, so that it will touch the sides of the browser viewport.

<div class="container-fluid px-0">
    This text hits the left side of the viewport.
</div>
like image 187
timgavin Avatar answered Sep 17 '22 07:09

timgavin