bootstrap 5 columns in one row - html

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!

Related

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;
}

Adding space between columns in Bootstrap 4 [duplicate]

This question already has answers here:
Add spacing between vertically stacked columns in Bootstrap 4
(6 answers)
Closed 4 years ago.
How I want it to look like:
I'm trying to add horizontal and vertical space between the columns in BS4 but it keeps either messing breakpoints around (black or red) or the breakpoints of bootstrap. Is there any easy way to add space? I've tried the new margin settings of BS4, but it didn't really help (messed up the heading and background-color). Also, the 2 horizontal columns should have the same height.
btw. If you run the snippet, the columns don't display correctly because of the size of the snippet output. That's what it should look like on non-mobile: screenshot (or expand the snippet)
* {
color: white;
}
.black {
background-color: black;
}
.red {
background-color: red;
}
nav {
background-color: antiquewhite;
margin: 0px;
}
.row {}
.head {
background-color: aqua;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" >
<nav class="navbar-static-top">
Nav
</nav>
<div class="container-fluid">
<div class="row p-1">
<div class="col black">
<div class="row">
<div class="col head">
HEADING 0 COLUMN
</div>
</div>
<p>aaaa<br>
aaaa</p>
</div>
</div>
<div class="row row-eq-height p-1">
<div class="col-md-6 black">
<div class="row">
<div class="col head">
HEADING 1 COLUMNS BLACK
</div>
</div>bbbb<br>
bbbb<br>
</div>
<div class="col-md-6 red">
<div class="row">
<div class="col head">
HEADING 2 CLOUMNS RED
</div>
</div>cccc
</div>
</div>
<div class="row p-1">
<div class="col black">
dddd
</div>
</div>
<div class="row p-1">
<div class="col black">
eeee
</div>
</div>
<div class="row row-eq-height p-1">
<div class="col-md-6 black">
<div class="row">
<div class="col head">
HEADING 3 COLUMNS BLACK
</div>
</div>ffff<br>
ffff<br>
</div>
<div class="col-md-6 red">
<div class="row">
<div class="col head">
HEADING 4 CLOUMNS RED
</div>
</div>hhhh
</div>
</div>
</div>
For spacing Bootstrap 4 has responsive spacing classes p-* (for padding) and m-* (for margins).
So, in your case, you could experiment by adding p-1 or maybe p-2 to all your columns to achieve the desired effect.
Note: The Bootstrap spacing classes are based on rem units, not on px because px is the old and outdated way of doing things when it comes to responsive design and accessibility.
Here's the reference link for you:
https://getbootstrap.com/docs/4.0/utilities/spacing/
The following code snippet produces the desired result by using nesting as well as the m-1 class to create margins around the columns:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
* {
color: white;
}
.black {
background-color: black;
}
.red {
background-color: red;
}
nav {
background-color: antiquewhite;
margin: 0px;
}
.head {
background-color: aqua;
}
</style>
<div class="container-fluid">
<div class="row">
<div class="col-12 col-md m-1">
<div class="row">
<div class="col black">
<div class="row">
<div class="col head">
HEADING 0 COLUMN
</div>
</div>
<p>aaaa<br>
aaaa</p>
</div>
</div>
</div>
</div>
<div class="row row-eq-height">
<div class="col-12 col-md m-1">
<div class="row">
<div class="col black">
<div class="row">
<div class="col head">
HEADING 1 COLUMNS BLACK
</div>
</div>
bbbb<br>
bbbb<br>
</div>
</div>
</div>
<div class="col-12 col-md m-1">
<div class="row h-100">
<div class="col red">
<div class="row">
<div class="col head">
HEADING 2 CLOUMNS RED
</div>
</div>cccc
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-md m-1">
<div class="row">
<div class="col black">
dddd
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-md m-1">
<div class="row">
<div class="col black">
eeee
</div>
</div>
</div>
</div>
<div class="row row-eq-height">
<div class="col-12 col-md m-1">
<div class="row">
<div class="col black">
<div class="row">
<div class="col head">
HEADING 3 COLUMNS BLACK
</div>
</div>
ffff<br>
ffff<br>
</div>
</div>
</div>
<div class="col-12 col-md m-1">
<div class="row h-100">
<div class="col red">
<div class="row">
<div class="col head">
HEADING 4 CLOUMNS RED
</div>
</div>hhhh
</div>
</div>
</div>
</div>
</div>

Bootstrap 4 row & column stacking vertically instead of horizontally

I feel like this should be easy, but I'm trying to get my .temp and .city divs to be side-by-side, but they're stacking vertically instead.
I've tried changing the size of the columns, but they always stack on top of each other. Any ideas?
<div class="col-lg" id="col2">
<div class="row">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="row">
<div class="col-lg" id="col3">
<div class="temp"></div>
<div class="city"></div>
</div>
</div>
</div>
You can wrap temp div and city div into 2 different columns. Check this Bootstrap4 Example.
.wind,
.temp,
.city {
height: 50px;
border: 1px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-sm" id="col2">
<div class="row">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="row">
<div class="col-lg" id="col3">
<div class="temp"></div>
</div>
<div class="col-lg" id="col3">
<div class="city"></div>
</div>
</div>
You can rearrange your html code to this format.
<div class="row">
<div class="col-lg" id="col2">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="col-lg" id="col3">
<div class="temp"></div>
<div class="city"></div>
</div>
</div>
You should edit your code to this, making the second row have two columns.
<div class="col-lg" id="col2">
<div class="row">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="row">
<div class="col temp"></div>
<div class="col city"></div>
</div>
</div>

Nested layout using bootstrap causes misalignment

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>