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?
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.
container has one fixed width for each screen size in bootstrap (xs,sm,md,lg); . container-fluid expands to fill the available width.
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.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With