Bootstrap 4 columns and rows producing unwanted padding [duplicate] - html

This question already has answers here:
Remove padding from columns in Bootstrap 3
(26 answers)
Remove gutter space for a specific div only
(11 answers)
Closed 4 years ago.
I am trying to use bootstrap to create columns and rows to place my images however too much padding is being added around the images which is preventing my images from looking like the design:
This is how I structured my HTML:
<!-- header -->
<header>
<div class="container">
<div class="row">
<div class="col-md-5">
<div class="col-md-12">
<img src="{!! $bg_image_col1_row1['url'] !!}" alt="{!! $bg_image_col1_row1['alt'] !!}" />
</div>
<div class="col-md-12">
<img src="{!! $bg_image_col1_row2['url'] !!}" alt="{!! $bg_image_col1_row2['alt'] !!}" />
</div>
</div>
<div class="col-md-7">
<div class="row">
<div class="col-md-6">
<img src="{!! $bg_image_co21_row1_col1['url'] !!}" alt="{!! $bg_image_co21_row1_col1['alt'] !!}" />
</div>
<div class="col-md-6">
<img src="{!! $bg_image_co21_row1_col2['url'] !!}" alt="{!! $bg_image_co21_row1_col2['alt'] !!}" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="container">
<h1>#php(get_field('front-page__title'))</h1>
<div>#php(get_field('front-page__slogan'))</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-md-9">
<div class="container">
<div class="zeo-cases-button">
#php(get_field('front-page__button--text'))
</div>
</div>
</div>
<div class="col-md-3">
<div class="container">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- /header -->
But this is resulting in this:
My question. Did I write the bootstrap elements correctly? How should I go about the padding in case the bootstrap elements are written correctly so that I can match the requirements of the design? Thanks a lot for your time!

Add the class no-gutters to each div class="row" to remove the spaces between the col-* elements
See the Bootstrap documentation about gutters.
<div class="row no-gutters">
<div style="background-color:#aaa" class="col-sm-3">a</div>
<div style="background-color:#bbb" class="col-sm-3">b</div>
<div style="background-color:#ccc" class="col-sm-3">c</div>
<div style="background-color:#ddd" class="col-sm-3">d</div>
</div>
Here a working jsfiddle that also removes the "visual padding" once the images doesn't fit 100% into the container.

Bootstrap : "The gutters between columns in our predefined grid classes can be removed with .no-gutters. This removes the negative margins from .row and the horizontal padding from all immediate children columns."
You should try to do :
<div class="row no-gutters">
<div class="col-6">
<img ... />
</div>
<div class="col-6">
<img ... />
</div>
</div>

Add below class hope it works for you.
.margin0-padding0 {
margin-left: 0px !important;
margin-right: 0px !important;
padding: 0px !important;
}

Related

Bootstrap 4 Row with Mixed Container and Container-Fluid Column

I'm trying to create a layout that looks like the component on the image.
It's a 12 col bootstrap grid. I'm looking to make the text take up 6 cols, 1 col spacer in-between the text and the last col, and then I'd like the last col (image) to take up the rest of the horizontal space, in and out of the container.
I've trying mixing the container and container-fluid classes (not advisable according to Bootstrap docs) and it doesn't work.
How would one achieve this type of a layout using Bootstrap 4?
Image:
Existing code:
<div class="info-side">
<div class="container-fluid">
<div class="row">
<div class="col-6">
<h2>#Model.TitleText</h2>
<p>#Model.AreaText</p>
</div>
<div class="col-1">
</div>
<div class="col-5">
<img src="#Model.Image.Url)" alt="#Model.Image.AlternativeText" style="width: 100%; height:100%;">
</div>
</div>
</div>
</div>
try this
<div class="info-side" >
<div class="container">
<div class="row col">
<div class="col-6 bg-info">
<h2>#Model.TitleText</h2>
<p>#Model.AreaText</p>
</div>
<div class="col-1 bg-warning">
</div>
<div class="col-5 bg-info">
<img src="#Model.Image.Url)" alt="#Model.Image.AlternativeText" style="width: 100%; height:100%;">
</div>
</div>
</div>
</div>
I added col to class row #div tag. It expands to all space available.
In another hand, mix containers regular and fluid is possible, but you have to take care of hierarchy: fluid is widest as regular, so regular must be included alone or inside a fluid class.
See this answer: link
Good Luck!
I've come to the following solution which creates the layout in my original image in the question.
I had to make one row position absolute, this way the two containers are overlapping each other.
<div class="info-side">
<div class="text-side container" style="position: relative;" >
<div class="text-area" style="position: absolute;">
<div class="row">
<div class="col-6 d-flex align-items-center" style="height: 600px;">
<div class="text-items">
<h2>#Model.TitleText</h2>
<p>#Html.Raw(Model.AreaText)</p>
</div>
</div>
</div>
</div>
</div>
<div class="image-side container-fluid">
<div class="row">
<div class="col-7"
<div class="col-5" style="height: 600px; ">
<img src="#Model.Image.Url" alt="#Model.Image.AlternativeText">
</div>
</div>
</div>
</div>

How to align height of neighboring columns in Bootstrap

I want to achieve something like this:
Here's what, I am currently getting in Bootstrap:
I want to achieve the following:
Width ratios must be such that Sites : User : Download = 2:8:2
Sites-Banner, Sites-Search, Download-Banner, Download-Summary all should have same heights
User-Login must have combined height of Sites-Banner & Sites-Search (or Download-Banner & Download-Summary)
Heights of Sites-List, User-Operations, Download-Details must be independent and can extend as long as required.
Here's my code: Fiddle (Check Update 1)
<div>
<div class="row">
<div class="col-2">
<div class="row">
<div class="col bg-primary">
<p id="sites-banner">Sites Banner</p>
</div>
</div>
<div class="row">
<div class="col bg-secondary">
<p id="sites-search">Sites Search</p>
</div>
</div>
<div class="row">
<div class="col bg-success">
<p id="sites-list">Sites List</p>
</div>
</div>
</div>
<div class="col-8">
<div class="row">
<div class="col bg-danger">
<p id="user-login">User Login</p>
</div>
</div>
<div class="row">
<div class="col bg-warning">
<p id="user-operations">User Operations</p>
</div>
</div>
</div>
<div class="col-2">
<div class="row">
<div class="col bg-info">
<p id="downloader-banner">Download Banner</p>
</div>
</div>
<div class="row">
<div class="col bg-light">
<p id="download-summary">Download Summary</p>
</div>
</div>
<div class="row">
<div class="col bg-dark">
<p id="download-details">Download Details</p>
</div>
</div>
</div>
</div>
</div>
I am not able to align the height of User-Login with Sites-Banner & Sites-Search [Done : Update 1]
Sites-List, User-Operations & Download-Details do not extend independently
Update 1: New Code
I got the User-Login to have combined height of Sites-Banner & Sites-Search, by wrapping them in a single row (<div class="row">)
But I am still not able to get the heights of Sites-List, User-Operations, Download-Details to be independent.
Update 2: New Code
Got the heights of Sites-List, User-Operations, Download-Details to be look independent.
But the there's lot of padding in between columns, which introduces white space in between and makes them look not aligned
Update 3: Fiddle
Although in Update 2 code it may look like that Sites-List, User-Operations & Download Details have different heights, they actually do not. They look so since we have applied background-color classes only to div element that contains the list.
For the issue regarding padding in between columns that can be solved by applying a mx-0 class attribute on the two rows, to make margin as 0
Rows have a negative margin of -15 px by default.
Checkout: Bootstrap negative margin on rows
Without mx-0 would cause a horizontal scrollbar on page. Checkout: Bootstrap columns cause horizontal scrollbar
Summary:
Treat row & col as Table's tr and td
Always put content in col
A col should necessarily have row as parent. Checkout: Bootstrap Grid Working & Guidlines
.col p{
margin: 0;
}
.user-login{
height: 100%
}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Downloader</title>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="bg-primary">
<p>Sites-Banner</p>
</div>
<div class="bg-secondary">
<p>Sites-Search</p>
</div>
</div>
<div class="col">
<div class="bg-danger user-login">
<p>User-Login</p>
</div>
</div>
<div class="col">
<div class="bg-info">
<p>Download-Banner</p>
</div>
<div class="bg-light">
<p>Download-Summary</p>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="bg-success">
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
<p>Sites-List</p>
</div>
</div>
<!-- <div class="clearfix"></div> -->
<div class="col">
<div class="bg-warning">
<p>User-Operations</p>
<p>User-Operations</p>
<p>User-Operations</p>
<p>User-Operations</p>
<p>User-Operations</p>
<p>User-Operations</p>
<p>User-Operations</p>
</div>
</div>
<!-- <div class="clearfix"></div> -->
<div class="col">
<div class="bg-dark">
<p>Download-Details</p>
<p>Download-Details</p>
<p>Download-Details</p>
<p>Download-Details</p>
</div>
</div>
</div>
</div>
</body>
</html>

bootstrap columns overlapping

I have an issue with bootstrap's grid layout. My columns are overlapping one another when I resize the screen to a smaller layout.
I'm not sure what the issue is.
Here is a picture of what is going on:
Here is my code
<div class='container-fluid'>
<div class="row"> <!-- 1 -->
<div class="col-sm-5 col-md-4">
<h1>JOHN SMITH</h1>
</div>
</div>
<div class='row'> <!-- 2 -->
<div class="col-sm-5 col-md-4">
<h2>VULCAN FLATBED</h2>
</div>
</div>
<div class="row"> <!-- 3 -->
<div class="col-sm-4 col-md-4 col-lg-4" style="background-color:yellow;">
<div class='row'>
<img src="vulcan.jpg" alt="vehicle image" width='391'/>
</div>
<div class='row'>
<button type='submit'>
<img src="book_now_button#2x.png" alt="book now">
</button>
</div>
</div>
<div class="col-sm-8 col-md-8 col-lg-8" style="background-color:pink;"> <!-- RIGHT SIDE -->
<div class='row'>
<h3>CAN HELP WITH</h3>
<p>LIFTING & YARD WORK</p>
</div>
<div class='row'>
<h3>AVAILABLE</h3>
<p>ALL WEEKENDS</p>
</div>
<div class='row'>
<h3>NOTE</h3>
<p>HI, MY NAME IS JOHN AND I HAVE A GREAT TRUCK FOR TRANSPORTING CARS,
WORK MATTERIAL, OR HEAVY OBJECTS. I HAVE A FULL TIME JOB SO I CAN
ONLY HELP YOU ON THE WEEKENDS. I LOVE WORKING WITH MY HANDS SO IF YOU
SOME HELP WITH LIFTING OR YARDWORK I AM YOUR GUY. BOOK NOW TO CONTACT
ME AND LET ME HELP YOU OUT.
</p>
</div>
</div>
</div> <!-- end 3 -->
<hr>
</div> <!-- end wrap -->
According to Bootstrap Docs, for each .row you need to have a .col-*-* as direct child but you don't have it in a few of them. Which cause the overflow.
Plus don't use the html tag width, it is deprecated. use class="img-responsive" from bootstrap to achieve max-width:100%
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class='container-fluid'>
<div class="row">
<!-- 1 -->
<div class="col-sm-5 col-md-4">
<h1>JOHN SMITH</h1>
</div>
</div>
<div class='row'>
<!-- 2 -->
<div class="col-sm-5 col-md-4">
<h2>VULCAN FLATBED</h2>
</div>
</div>
<div class="row">
<!-- 3 -->
<div class="col-sm-4 col-md-4 col-lg-4" style="background-color:yellow;">
<div class='row'>
<div class="col-xs-12">
<img class="img-responsive" src="//lorempixel.com/500/200" alt="vehicle image" />
</div>
</div>
<div class='row'>
<div class="col-xs-12">
<button type='submit'>
<img src="book_now_button#2x.png" alt="book now">
</button>
</div>
</div>
</div>
<div class="col-sm-8 col-md-8 col-lg-8" style="background-color:pink;">
<!-- RIGHT SIDE -->
<div class='row'>
<div class="col-xs-12">
<h3>CAN HELP WITH</h3>
<p>LIFTING & YARD WORK</p>
</div>
</div>
<div class='row'>
<div class="col-xs-12">
<h3>AVAILABLE</h3>
<p>ALL WEEKENDS</p>
</div>
</div>
<div class='row'>
<div class="col-xs-12">
<h3>NOTE</h3>
<p>HI, MY NAME IS JOHN AND I HAVE A GREAT TRUCK FOR TRANSPORTING CARS, WORK MATTERIAL, OR HEAVY OBJECTS. I HAVE A FULL TIME JOB SO I CAN ONLY HELP YOU ON THE WEEKENDS. I LOVE WORKING WITH MY HANDS SO IF YOU SOME HELP WITH LIFTING OR YARDWORK I
AM YOUR GUY. BOOK NOW TO CONTACT ME AND LET ME HELP YOU OUT.
</p>
</div>
</div>
</div>
I believe your problem is that you have many elements with the "row" class that don't have any columns in them. The hierarchy goes container > row > col. Without a column, there is no need for anything to be declared a row, and it affects the layout in unusual ways without them.
Another problem is your image. Remove the "width" attribute, and add the following class attribute: class="img-responsive". See the Images section of the bootstrap docs for details.
In my case, I was using box-sizing: content-box; for all my elements in css. That is why padding was creating problems with overall computed width of the elements. So, I changed it to box-sizing: border-box; from box-sizing: content-box;
Ref:
https://getbootstrap.com/docs/4.0/getting-started/introduction/#box-sizing

Bootstrap Dynamic Layout Change

I am currently using bootstrap on a website which is displaying an ecommerce store.
The current layout is 3 columns of items within 4 rows, but I am wanting to implement a button which will change it to 2 columns.
I have done so, however the code seems to be causing some issues in that the layout changes to
Two Items
One Item
Two Items
One Item
Each one Item row has a large area of white space where an item could go.
The Code below shows one "Row" which is in the three column layout. I have used javascript which changes the class 'col-sm-4' to 'col-sm-6'. Where is my mistake here?
<div class="row"><!-- row 2 -->
<div class="col-sm-4 product-category-display">
<div class="row">
<img src="assets/img/products/women/jackets_coats/raina_parka.png" class="product-image">
</div>
<div class="row product-status">
<span class="products-status-sale">Sale</span>
</div>
<div class="row">
<p class="product-name col-sm-12"<p>Raina Waterproof Parka</p>
</div>
<div class="row product-price">
<span>£99.00</span>
</div>
</div>
<div class="col-sm-4 product-category-display">
<div class="row">
<img src="assets/img/products/women/jackets_coats/april_jacket.png" class="product-image">
</div>
<div class="row product-status">
<span></span>
</div>
<div class="row">
<p class="product-name col-sm-12">April Waterproof Front Pocket Jacket</p>
</div>
<div class="row product-price">
<span>£99.95</span>
</div>
</div>
<div class="col-sm-4 product-category-display">
<div class="row">
<img src="assets/img/products/women/jackets_coats/free_delivery.png" class="product-image">
</div>
<div class="row product-status">
<span></span>
</div>
<div class="row">
<p></p>
</div>
<div class="row product-price">
<span></span>
</div>
</div>
</div><!-- end row 2 -->
The columns should only add upto 12. When you change 4 to 6 its becomes 18.
<div class="row">
<div class="col-lg-4"></div><div class="col-lg-4"></div><div class="col-lg-4"></div>
</div>
Problem solved. I just had to remove all of the rows and tweak the JS to add the class

Bootstrap Center Scafolding

I'd have two "sections" in which I am using the bootstrap 3 scaffolding to style. I am having a hard time figuring out how I might have these maintain their column spacing while still be centered on the middle of the page. For example right now it is
<content><content> ---<space>---
and i want
---<space>--- <content><content> ---<space>---
Here is what i've got.
<div class=".container-fluid" id="aboutContent">
<div class="col-md-3">
<img src="../imgs/pic.jpg" alt="Joe Brunett" id="aboutPicture"/>
</div>
<div class="well col-md-4" id="desc">
<p> text<p>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3"></div>
</div>
</div>
Offsets can be used to center a div but remember that it'll work only for even columns
<div class="col-md-8 col-md-offset-2"></div>
You can even change the break-point by replacing
<div class="col-md-6 col-md-offset-3"></div>
with
<div class="col-sm-6 col-sm-offset-3"></div>