Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

container-fluid and side padding with Bootstrap 3

I want my page's content to take up the full width of the screen with a little padding on the right and left and be fluid, but when I wrap my div.row and div.col-md-x in a <div class="container-fluid"> the page's content touches the sides of the screen.

    <link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-6">

What is the proper, Bootstrap way to have a 100% width, fluid layout, and 15px padding on the left and right?

like image 711
Andrew Koper Avatar asked Aug 16 '14 21:08

Andrew Koper


People also ask

Do Bootstrap containers have padding?

Containers are the most basic layout element in Bootstrap and are required when using our default grid system. Containers are used to contain, pad, and (sometimes) center the content within them.

What is container and container-fluid in Bootstrap?

container has one fixed width for each screen size in bootstrap (xs,sm,md,lg); . container-fluid expands to fill the available width.

How do you remove padding from container-fluid Bootstrap?

Use px-0 on the container and no-gutters on the row to remove the paddings. Quoting from Bootstrap 4 - Grid system: Rows are wrappers for columns.


2 Answers

You can try an id to <div id="bd" class="container-fluid"> and if add this script after add Jquery you can padding when window resize, and can add more resolutions px with more "if" or only add padding-left or right.

<script>
  $(document).ready(function(){

    function paddingbd(){
      if($(window).width()>800){
        $("#bd").css("padding","30px");
      }else{
        $("#bd").css("padding","");
      }
    }

    paddingbd();

    $(window).on("resize",paddingbd);

  });
<script>
like image 32
Raul Fernandez Marques Avatar answered Oct 05 '22 07:10

Raul Fernandez Marques


As per the Bootstrap docs:

Use .container-fluid for a full width container, spanning the entire width of your viewport.

If you want 15px padding then add to your CSS:

.container-fluid {
    padding: 15px;
}

However you may want to use a percent (padding: 2%) or media queries since 15px will look different on different screen resolutions.

Another option: use <div class="container"> instead of <div class="container-fluid">. This will give you built in padding.

Bootply demo

like image 144
Dan Avatar answered Oct 05 '22 07:10

Dan