I been trying to display below attached image vertical column wise Grid view using Bootstrap in HTML. Can give me some idea for how we can achieve this .
Now i am normally display row wise column grid with reference of Grid systems on w3school.but this are not responsive to mobile view. So I need to display on vertical
Thank you in advance !!
I divided thesection into vertical columns. Inside each column I inserted row class to further divide row into column.
h2,h1 {
background-color: #ffffff;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<section class="text-center clearfix">
<!-- Divided sections into column-->
<div class="col-4 float-left" style="background-color:red">
<h1>col-1</h1>
<!-- Each column contains row-->
<div class="row" style="background-color: #ff3333">
<!-- You can further divide vertical column-->
<div class="col-6">
<h2>item-1(a)</h2>
</div>
<div class="col-6">
<h2>item-1(b)</h2>
</div>
</div>
<div class="row" style="background-color: #ff4d4d">
<h2>item-2</h2>
</div>
</div>
<div class="col-4 float-left" style="background-color:green">
<h1>col-2</h1>
<div class="row" style="background-color:#1aff66">
<h2>item-1</h2>
</div>
</div>
<div class="col-4 float-left" style="background-color:blue">
<h1>col-3</h1>
<div class="row" style="background-color: #0069cc">
<h2>item-1</h2>
</div>
<div class="row" style="background-color: #4d94ff">
<h2>item-2</h2>
</div>
<div class="row" style="background-color: #b3d1ff">
<h2>item-3</h2>
</div>
<div class="row" style="background-color: #cce6ff">
<h2>item-4</h2>
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
For vertical column wise Grid view you can use
$('.grid').masonry({
// set itemSelector so .grid-sizer is not used in layout
itemSelector: '.grid-item',
// use element for option
columnWidth: '.grid-sizer',
percentPosition: true
})
.grid-sizer,
.grid-item { width: 20%; }
/* 2 columns */
.grid-item--width2 { width: 40%; }
<div class="grid">
<!-- width of .grid-sizer used for columnWidth -->
<div class="grid-sizer"></div>
<div class="grid-item"></div>
<div class="grid-item grid-item--width2"></div>
...
</div>
Masonry is a JavaScript grid layout library. It works by placing elements in optimal position based on available vertical space, sort of like a mason fitting stones in a wall.
You can use this link for reference
https://masonry.desandro.com/
You can use bootstrap 4 flex utility
https://getbootstrap.com/docs/4.0/utilities/flex/
Related
I have two side-by-side cards with nested rows that contain dynamic content, and I want the first row of the first card to be the same height as the first row of the second card, the second row of the first card to be the same height at the second row of the second card, etc.
I would want the heights to be calculated in the following way: height of A1 = max(height of A1, height of A2), height of A2 = max(height of A1, height of A2), height of B1 = max(height of B1, height of B2), height of B2 = max(height of B1, height of B2).
Here is my code:
<div class="row">
<div class="col-lg-6 mb-3">
<div class="card">
<div class="card-body">
<div id="a1" class="row">
...
</div>
<div id="b1" class="row">
...
</div>
</div>
</div>
</div>
<div class="col-lg-6 mb-3">
<div class="card">
<div class="card-body">
<div id="a2" class="row">
...
</div>
<div id="b2" class="row">
...
</div>
</div>
</div>
</div>
</div>
This is what I currently have:
This is what I want:
How do I do this using only Bootstrap 4 and CSS?
You aren't going to do this with Bootstrap cards. You need to fake them using custom borders on a CSS grid, where one card spans two rows. You'll also have to forego the wrapper elements since they interfere with the flow of the rows.
Also, if you want the "cards" to stack on mobile you'll need to undo that with a media query at your desired breakpoint (Bootstrap is mobile-first, so we should be with our styles as well). I've done so at 992px, which is Bootstrap's "large", to match the column classes you had implemented. See the standard demo for the mobile layout and the full page demo for the desktop layout. Notice that extra whitespace doesn't occur on mobile, which I think is appropriate.
Unfortunately, Bootstrap 4 doesn't provide CSS grid, so we'll use custom styles. The good news is that we maintain proper semantic order of your document content. Related content is still together. If you organize further with headings and paragraphs it'll be nicely accessible.
.grid>div {
margin: 1rem;
padding: 1rem;
border: 1px solid rgba(0, 0, 0, .125);
}
.grid> :nth-child(odd) {
border-bottom: 0;
border-radius: 0.25rem 0.25rem 0 0;
margin-bottom: 0;
background: rgba(255, 0, 0, 0.1); /* for demo only */
}
.grid> :nth-child(even) {
border-top: 0;
border-radius: 0 0 0.25rem 0.25rem;
margin-top: 0;
}
#media (min-width: 992px) {
.grid {
display: grid;
grid-template-rows: auto auto;
grid-auto-flow: column;
}
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.1/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn" crossorigin="anonymous">
<div class="grid">
<div id="a1">
A1: I have two side-by-side cards with nested rows that contain dynamic content.
</div>
<div id="b1">
B1: I want the first row of the first card to be the same height as the first row of the second card, the second row of the first card to be the same height at the second row of the second card, etc. I would want the heights to be calculated in the following
way.
</div>
<div id="a2">
A2: I want the first row of the first card to be the same height as the first row of the second card, the second row of the first card to be the same height at the second row of the second card, etc.
</div>
<div id="b2">
B2: I have two side-by-side cards with nested rows that contain dynamic content.
</div>
</div>
I can do this using jQuery ,
var maxHeight = function(elems){
return Math.max.apply(null, elems.map(function ()
{
return $(this).height();
}).get());
}
$('.a').css('height',maxHeight($(".a")));
$('.b').css('height',maxHeight($(".b")));
.col-6{
border:1px solid black;
padding:5px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row p-2">
<div class="col-6">
<div class="row match-height">
<div class="col-12 ">
<div class="card a">
<div class="card-body">
#A1
<br>
Extraa
</div>
</div>
</div>
</div>
<div class="row match-height">
<div class="col-12 ">
<div class="card b">
<div class="card-body">
#B1
</div>
</div>
</div>
</div>
</div>
<div class="col-6">
<div class="row match-height">
<div class="col-12">
<div class="card a">
<div class="card-body">
#A2
</div>
</div>
</div>
</div>
<div class="row match-height">
<div class="col-12">
<div class="card b">
<div class="card-body">
#B2
</div>
</div>
</div>
</div>
</div>
</div>
I am looking for a technique to handle responsivity in html pages that have column-like structures with multiple items.
Here is an example:
Codepen
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row" style="width:200;">
<div class="col-sm-6">
<div class="item">
First
<br><br>
</div>
<div class="item">
Second Second Second Second Second Second Second
<br><br>
</div>
<div class="item">
Third<br><br>
</div>
</div>
<div class="col-sm-6">
<div class="item">
First First First First First<br><br>
</div>
<div class="item">
Second<br><br>
</div>
<div class="item">
Third<br><br>
</div>
</div>
</div>
I would like it to look like this:
The height of each "item" needs to grow and shrink dynamically according to the length of its text and browser-window width, while staying aligned with the other column.
I also need that when the screen is narrow enough, the right column should move under the left column.
My problem is that for Bootstrap, I seem to need to place each column into a separate div.
On the other hand, when the columns appear side by side, if I want corresponding items to appear at the same height, I need to separate them into rows and not columns.
PS. I tried display:flex but could not find a way that works.
Any ideas?
Thanks
Arie
If you use BS3 but are willing to use flex aside, you can consider grid instead inside a mediaquerie and a custom class :
Your comment I react to:
Thanks G-Cyrillus. Is it possible to do that with Flex and Bs3? This is a large website which is built entirely with BootStrap3, and upgrading to Bs4 is currently not an option.
possible example with BS3, using a custom class inside a mediaquerie:
/*see us, demo purpose */
.row div {
box-shadow: 0 0 0 1px
}
/* custom class for the breakpoint where rows are drawn into columns with matching rows */
#media screen and (max-width: 992px) and (min-width:768px) {
:before,
:after {
grid-row: -1
}
.grid-md-2 {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-auto-flow: row dense;
}
.grid-md-2 [class^="col"] {
width: 100%;
grid-column: 1;
}
/*.grid-md-2 [class^="col"]:nth-child(3)~[class^="col"]*/
/* update for a repeating pattern */
.grid-md-2 [class^="col"]:nth-child(6n -2),
.grid-md-2 [class^="col"]:nth-child(6n -1),
.grid-md-2 [class^="col"]:nth-child(6n) {
grid-column: 2;
}
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row grid-md-2">
<div class="col-sm-6 col-md-4 col-xs-12">
First
</div>
<div class="col-sm-6 col-md-4 col-xs-12">
Second
</div>
<div class="col-sm-6 col-md-4 col-xs-12">
Third
</div>
<div class="col-sm-6 col-md-4 col-xs-12">
First First First
<br><br> First First
</div>
<div class="col-sm-6 col-md-4 col-xs-12">
Second<br>Second
</div>
<div class="col-sm-6 col-md-4 col-xs-12">
Third
</div>
</div>
</div>
The Bootstrap Grid layout is already dynamic in nature, so you don't need the style attribute for row width.
For the right column to go under the left column in the mobile view, use the bootstrap grid for mobile view. So just add the mobile view grid layout class name for each column div element.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-sm-6 col-xs-12">
<div class="item">
First
<br><br>
</div>
<div class="item">
Second Second Second Second Second Second Second
<br><br>
</div>
<div class="item">
Third<br><br>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="item">
First First First First First<br><br>
</div>
<div class="item">
Second<br><br>
</div>
<div class="item">
Third<br><br>
</div>
</div>
</div>
For more visit Visit Here.
I am designing a stair grid for showing the growth of a child in 4 up steps.
What I did is: created four rows containing 4 columns. From the first div, I removed the first three column and put content in fourth. Similarly, on next bottom div I put content in the third column then in next bottom filled the second column.
After all these, I put top margin negative so that it looks like a stair.
I know this is not a good approach. How can I improve that?
I want it to be like this:
Current code:
<!--Here i have used the last column and col-md-9 remains blank-->
<!-- First row -->
<div class="row">
<div class="col-md-9"></div>
<div class="col-md-3 ml-md-auto bg-alert">
<img src="img/career/info2/4.png" class="img-responsive">
</div>
</div>
<!--Here i have used the second last column and col-md-6 remains blank-->
<!-- secondrow -->
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-3" style="margin-top:-14rem;">
<img src="img/career/info2/3.png" class="img-responsive">
</div>
<div class="col-md-3"></div>
</div>
<!--Here i have used second column and remains blank-->
<!-- Third row -->
<div class="row">
<div class="col-md-3 ml-md-auto"></div>
<div class="col-md-3 ml-md-auto" style="margin-top:-37rem;">
<img src="img/career/info2/2.png" class="img-responsive">
</div>
<div class="col-md-3"></div>
<div class="col-md-3 ml-md-auto"></div>
</div>
<!--Here i have used the first column and col-md-9 remains blank-->
<!-- Fourth row -->
<div class="row">
<div class="col-md-3">
<img src="img/career/info2/1.png" class="img-responsive">
</div>
<div class="col-md-9"></div>
</div>
Here's one way to solve this problem:
You put 4 columns into one single .row and then add 3 custom classes to the first 3 columns (.step-1 / .step-2 / .step-3).
Using #media (min-width: 768px) you ensure that those custom classes only kick in on medium (md) screens or larger. Then you add margin-top to each column as needed to push it down.
On screens that are smaller than md the 4 columns will stack up in the right order without any top margins affecting them.
Click the "run code snippet" button below and expand to full page:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
#media (min-width: 768px) {
.step-1 {
margin-top: 150px;
}
.step-2 {
margin-top: 100px;
}
.step-3 {
margin-top: 50px;
}
}
</style>
<div class="container">
<div class="row">
<div class="col-md-3 step-1">Step 1</div>
<div class="col-md-3 step-2">Step 2</div>
<div class="col-md-3 step-3">Step 3</div>
<div class="col-md-3">Step 4</div>
</div>
</div>
http://i.imgur.com/Wkt3BRt.png
Bootstrap seems to have skipped 11 cols, I'm having trouble with aligning everything.
You need to have the col-md- named classes divs in a row class.
For example -
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-5"></div>
<div class="col-md-2"></div>
<div class="col-md-1"></div>
</div>
Go with link for more details
If you would put your code here we would have a better idea of your problem.
Having said that, I leave you some general tips:
Some Bootstrap grid system rules:
Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding
Use rows to create horizontal groups of columns
Content should be placed within columns, and only columns may be immediate children of rows
Predefined classes like .row and .col-sm-4 are available for quickly making grid layouts
Columns create gutters (gaps between column content) via padding. That padding is offset in rows for the first and last column via
negative margin on .rows
Grid columns are created by specifying the number of 12 available columns you wish to span. For example, three equal columns would use
three .col-sm-4
Here the full info: http://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
Here an snippet example to illustrate:
.show-grid [class^="col-"]{
padding-top: 10px;
padding-bottom: 10px;
border: 1px solid #AAA;
background-color: #EEE;
background-color: rgba(200, 200, 200, 0.3);
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row show-grid">
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
<div class="col-xs-1">.col-1</div>
</div>
<div class="row show-grid">
<div class="col-xs-8">.col-8</div>
<div class="col-xs-4">.col-4</div>
</div>
<div class="row show-grid">
<div class="col-xs-4">.col-4</div>
<div class="col-xs-4">.col-4</div>
<div class="col-xs-4">.col-4</div>
</div>
<div class="row show-grid">
<div class="col-xs-6">.col-6</div>
<div class="col-xs-6">.col-6</div>
</div>
I'm using Bootstrap 3. I have two rows. The first row has 4x3 columns. The second row has one column of 3 and one column of 9. The column of 9 has twice the height of all the other columns. I would like a column added beneath the column of 3 on the second row. I have made an image to explain it.
Green is on one row and purple is on one row. I have tried to put yellow in it's own row, but then it is displayed on the left though but not against the bottom of the small purple block.
I have also put the small purple and yellow blocks on the same row but they get displayed next to each other with the 90 block underneath them.
why you don't follow this
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
</div>
<div class="row">
<div class="col-md-3">
<div class="row">
<div class="col-md-12"></div>
<div class="col-md-12"></div>
</div>
</div>
<div class="col-md-9">
<div class="col-md-12"></div>
</div>
</div>
and later you could trick it with css
The Bootstrap grid system controls column width but not height. You can achieve your desired layout with the expected grid pattern and use height rules to make the bottom edge flush.
http://jsfiddle.net/rblakeley/ruggnzvq/
<html>
<head>
<title>Bootstrap grid example</title>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style type="text/css">
div[class^="col"] { height: 40px; text-align: center; border: 1px dashed red; background: #fcc;}
.row:nth-child(2) div[class^="col"] { background: #cfc;}
.row:nth-child(2) > div[class^="col"]:first-child { border: none;}
.row:nth-child(2) > div[class^="col"]:nth-child(2) { height: 100px;}
.row:nth-child(2) .row div[class^="col"]:nth-child(2) { height: 60px; background: #ccf;}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-xs-3">3</div>
<div class="col-xs-3">3</div>
<div class="col-xs-3">3</div>
<div class="col-xs-3">3</div>
</div>
<div class="row">
<div class="col-xs-3">
<div class="row">
<div class="col-xs-12">3</div>
<div class="col-xs-12">3</div>
</div>
</div>
<div class="col-xs-9">9</div>
</div>
</div>
</body>
</html>