Nested layout using bootstrap causes misalignment - html

I am trying to create a nested layout using bootstrap 3. I followed the the tutorial (see the part regarding nesting). The layout basically only contains rows consisting of single columns, however I still need the nesting for technical reasons. My current version is in this fiddle.
In a nutshell, I use alternating row / column divs to achieve the nesting:
<div class="row">
<div class="col">
<div class="row">
<div class="col">
Content row 1 (misaligned)
</div>
</div>
</div>
</div>
The problem is that the inner content is misaligned with respect to the surrounding one. I suspect that this is because rows have a negative margin. Is there a way to fix or circumvent this problem?

There is no .col definition for bootstrap 3.
TWBS-3#css#grid syntax is: .col-${screen}-${span} where:
screen = ['xs', 'sm', 'md', 'lg']
span = [1-12]
So, assuming you want to work with extra small screens your html should look like:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<section class="container">
<div class="row">
<div class="col-xs-12">
<div class="row">
<div class="col-xs-12">
Content row 1 (misaligned)
</div>
</div>
</div>
</div>
</section>
here is the official example using screen = xs
.txt {
background: cyan;
height: 20px;
display: flex;
margin: 3px 0;
align-items: center;
justify-content: center;
}
.row { margin-bottom: 50px; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<section class="container">
<div class="row">
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
<div class="col-xs-1"><div class="txt">1</div></div>
</div>
<div class="row">
<div class="col-xs-8"><div class="txt">.col-xs-8</div></div>
<div class="col-xs-4"><div class="txt">.col-xs-4</div></div>
</div>
<div class="row">
<div class="col-xs-4"><div class="txt">.col-xs-4</div></div>
<div class="col-xs-4"><div class="txt">.col-xs-4</div></div>
<div class="col-xs-4"><div class="txt">.col-xs-4</div></div>
</div>
<div class="row">
<div class="col-xs-6"><div class="txt">.col-xs-6</div></div>
<div class="col-xs-6"><div class="txt">.col-xs-6</div></div>
</div>
</section>

there is no class called ".col1" in bootstrap. you need to give proper column class to get rid if the row margin. try to use the blow code
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 "> Content row 1</div>
<div class="col-xs-4 col-sm-4 col-md-4"> Content row 2 </div>
<div class="col-xs-4 col-sm-4 col-md-4"> Content row 3 </div>
</div>

Related

bootstrap 5 columns in one row

Five equal columns in twitter bootstrap
Bootstrap - 5 column layout
5 columns per row in Bootstrap-4
I have already looked at these links but still not found an issue
I have tried to get 5 columns in a row with below
css
.col-xs-offset-13{
margin-left:4.166666667%;
}
html
<div class="col-xs-2">1</div>
<div class="col-xs-2 col-xs-offset-13">2</div>
<div class="col-xs-2 col-xs-offset-13">3</div>
<div class="col-xs-2 col-xs-offset-13">4</div>
<div class="col-xs-2 col-xs-offset-13">5</div>
but the result I get is 6 columns in a row. any ideas would be appreciated
you can use a col-xx class without a column size :
div div div {
border: solid;
margin: 2px;/* this can be added without breaking the row */
}
div div div:before {
content:attr(class);/* show class used */
color:crimson
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<p>Class used , play snippet in full page to test behavior on resizing :</p>
<div class="container">
<div class="row">
<div class="col-sm"></div>
<div class="col-sm"></div>
<div class="col-sm"></div>
<div class="col-sm"></div>
<div class="col-sm"></div>
</div>
<div class="row">
<div class="col-md"></div>
<div class="col-md"></div>
<div class="col-md"></div>
<div class="col-md"></div>
<div class="col-md"></div>
</div>
<div class="row">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>
</div>
Include in your CSS style:
.custom-col{
width: 20%;
word-break:break-all;
}
HTML:
<div class="row">
<div class="custom-col">CONTENT</div>
<div class="custom-col">CONTENT</div>
<div class="custom-col">CONTENT</div>
<div class="custom-col">CONTENT</div>
<div class="custom-col">CONTENT</div>
</div>
It worked for me!

How to merge 2 rows and 2 columns to become 1 big box in Bootstrap 4?

How to merge 2 rows and 2 columns to become 1 big box in Bootstrap 4?
Before:
To be like this:
HTML
<div class="container">
<div class="row">
<div class="col-3">.col-3</div>
<div class="col-3">.col-3</div>
<div class="col-3">.col-3</div>
<div class="col-3">.col-3</div>
</div>
<div class="row">
<div class="col-3">.col-3</div>
<div class="col-3">.col-3</div>
<div class="col-3">.col-3</div>
<div class="col-3">.col-3</div>
</div>
</div>
I have made some changes to your html structure, also used some b-4 classes (h-100) to align it. read boostrap-4 document to understand grid system.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col">
<div class="row">
<div class="col border">.col-3</div>
<div class="col border">.col-3</div>
<div class="w-100"></div>
<div class="col border">.col-3</div>
<div class="col border">.col-3</div>
</div>
</div>
<div class="col">
<div class="row h-100">
<div class="col border h-100">.col-3</div>
</div>
</div>
</div>
</div>
Hope this helps. Note i did not add background colors or classes to keep the answer clean
<div class="row">
<div class="col-sm-6">
<div class="row">
<div class="col-sm-6">A</div>
<div class="col-sm-6">B</div>
</div>
<div class="row">
<div class="col-sm-6">C</div>
<div class="col-sm-6">D</div>
</div>
</div>
<div class="col-sm-6">
F
</div>
</div>
JSFIDDLE LINK

How to make 4 columns in bootstrap grid break to two then one column

Here is my bootstrap code so far:
<div class="container-flex">
<div class="row">
<div class="col-lg-3">1</div>
<div class="col-lg-3">2</div>
<div class="col-lg-3">3</div>
<div class="col-lg-3">4</div>
</div>
</div>
A simple 4 column setup. Currently it breaks into single column on large (lg class) breakpoint. Is there any way I can set it up so it breaks into two columns on large breakpoint then into one column on medium (md class ) breakpoint? I've been looking over bootstrap tutorials and can't find any solution.
Here's my jsfiddle: https://jsfiddle.net/noe562h0/
Try this
<div class="container-flex">
<div class="row">
<div class="col-12 col-md-6 col-lg-3">1</div>
<div class="col-12 col-md-6 col-lg-3">2</div>
<div class="col-12 col-md-6 col-lg-3">3</div>
<div class="col-12 col-md-6 col-lg-3">4</div>
</div>
</div>
Here are Bootstrap 4 grid references Bootstrap and w3schools.com documentation.
If you want to break differently, you have to use different breakpoint. Like this:
<div class="container-flex">
<div class="row">
<div class="col-lg-6 col-md-12">1</div>
<div class="col-lg-6 col-md-12">2</div>
<div class="col-lg-6 col-md-12">3</div>
<div class="col-lg-6 col-md-12">4</div>
</div>
</div>
Check the below fiddle:
Grid Breakdown
https://jsfiddle.net/x4rjp1gq/
<div class="container-flex">
<div class="row">
<div class="col-lg-3">
<div class='col'>1</div>
<div class='col'>2</div>
</div>
<div class="col-lg-3">
<div class='col'>3</div>
<div class='col'>4</div>
</div>
</div>
</div>
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
text-align:center;
}

bootstrap 4: difference between adding a row or adding a col-12?

I am trying to clarify this doubt, but on the documentation on bootstrap 4 isn't specified.
What is the difference between these two snippet:
<div class="container">
<div class="row">
<div class="col-12">col-12</div>
</div>
<div class="row">
<div class="col-6">col-6</div>
<div class="col-6">col-6</div>
</div>
</div>
And, just using a single .row:
<div class="container">
<div class="row">
<div class="col-12">col-12</div>
<div class="col-6">col-6</div>
<div class="col-6">col-6</div>
</div>
</div>
That is: adding a specific new .row, or simply adding a col-12 ?
If you add more than col-12 to a row, bootstrap system simply breaks after col-12 in your example.
<div class="container">
<div class="row">
<div class="col-12">col-12</div>
<div class="col-6">col-6</div>
<div class="col-6">col-6</div>
</div>
</div>
Writing like this is totally fine.

Grid with container-fluid and container in Bootstrap 3

I have been using html/css for a while now. And I have never ran into this kind of grid problem with Bootstrap 3. I am trying to find a way to combine a 50% width (inside a <div class="container-fluid">) with a 50% width div (inside a <div class="container">). Like the grid in the following picture:
Example of the template
Yellow overlay: <div class="container"></div>
The problem is that they won't work together cause of the widths.
So how do I simulate this?
<section>
<div class="container-fluid">
<div class="col-sm-12 col-md-6 no-padding"></div>
<div class="container">
<p>content</p>
</div>
</div>
<div class="col-sm-12 col-md-6 no-padding photo"></div>
</div>
</section>
If I'm understanding what you're trying to achieve, there are a couple of problems. Firstly, you still need a row div to wrap the columns, which is in turn nested in the container. Also, by default, the container would have some padding, so that would need to be removed with some basic CSS as well.
Here is the HTML structure
<div class="container-fluid">
<div class="row">
<div class="col-lg-6" id="left">
Left Side
</div>
<div class="col-lg-6" id="right">
Right Side
</div>
</div>
</div>
Also, here's a live example you can play with: http://www.bootply.com/MKe7aJwKuc
Let me know if I missed the mark on what you're trying to do and I can try to rework it and help you out.
Should be this schema
<section>
<div class="container-fluid">
<div class="col-sm-12 col-md-6 no-padding"></div>
<div class="col-sm-12 col-md-6 no-padding photo"></div>
<div class="container">
<div class= "row">
<div class="col-sm-12 col-md-6 no-padding">Content</div>
<div class="col-sm-12 col-md-6 no-padding photo"></div>
</div>
</div>
</div>
</section>
on Bootstrap 4
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="elem left">Left Side</div>
</div>
<div class="col-lg-6">
<div class="elem right">Right Side</div>
</div>
</div>
</div>
sass
#mixin fluidwidth($widths: $container-max-widths, $breakpoints: $grid-breakpoints) {
#each $breakpoint, $container-max-width in $widths {
#include media-breakpoint-up($breakpoint, $breakpoints) {
width: calc(100% + ((100vw - #{$container-max-width})/2) );
}
}
}
.elem.right{#include fluidwidth;}