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>
Related
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 created a column structure with bootstrap 4 . It looks something like this it has 1 row with 2 columns:
<div class="left">
<hr class="container hline">
<div id="main" class="container border">
<div class="row">
<div class="col-lg-5 top">
</div>
<div class="col-lg-5 top">
/*Widget with too much margin right*/
</div>
</div>
</div>
</div>
The issue is that the widget on the right has too much empty space. The columns have an equal length (col-lg-5) but there is still a lot of space on the right. How can I remove this and keep the columns the same size?
link to codepen
You should only use columns within your rows, and the columns are based on a 12 column grid. You currently have 10 columns worth of width taken up using 2 .col-5 column and you also have a pixel for the divider that is stuck into the row in the codepen even though your example here doesn't show it.
How about doing two .col-6 columns and having the divider be a left border on the right column?
https://codepen.io/anon/pen/xaeWGB
<div class="left">
<hr class="container hline">
<div id="main" class="container border">
<div class="row">
<div class="col-lg-6 top">
</div>
<div class="col-lg-6 divider top">
</div>
</div>
</div>
</div>
So basically I'm still a begginer when it comes to doing interfaces on the web and trying to allign everything properly. I've decided to use the bootstrap library. I'm trying to make a modal dialog divided into multiple section but i'm really struggling to make some section stack on top of each other and have another section take up the entire space.
What I currently have :
https://i.gyazo.com/adeeb3cca0abb6dea4a5d002d3568afa.png
What I'm trying to achieve :
https://i.gyazo.com/e8513c243424cb71926ac838e8b1166e.png
This is the code I currently have with some sample text to try to delimiter each section :
<div class='container-fluid'>
<div class="row">
<div class="col-md-3" style='border:1px solid black;max-height:5vh;'>
STATUS
</div>
<div class="col-md-9" style='border:1px solid black;min-height:50vh;'>
L
</div>
<div class="col-md-3">
SOME TEXT ASDASDASDJLASDJKLASDJAD
ASDASDLASKD
aASDASDK:ASDKASDK
ASDASJDASDASDKASJDASDJ
</div>
<div class="col-md-9">
L
</div>
</div>
</div>
To match the image you've provided, you want two columns - one three wide with four rows, and one nine wide with one row.
The height of the rows in the left column will be determined by their contents. I've written an example with extra content in one row in the left column:
<div class="container">
<div class="row">
<div class="col-sm-3">
<div class="row">
3
</div>
<div class="row">
3<br>
wide<br>
but<br>
taller
</div>
<div class="row">
3
</div>
<div class="row">
3
</div>
</div>
<div class="col-sm-9">
9
</div>
</div>
</div>
JSFiddle for a live example.
You keep two main columns (3/9) and inside the first column you can add more container. You can also add styles or classes to them.
<div class="container-fluid">
<div class="row" >
<div class="col-md-3" style='border:1px solid black;min-height:50vh;'>
<div style="min-height:10vh">10vh</div>
<div style="min-height:20vh">10vh</div>
<div style="min-height:10vh">10vh</div>
<div style="min-height:10vh">10vh</div>
</div>
<div class="col-md-9" style='border:1px solid black;min-height:50vh;'>L</div>
</div>
</div>
I'm trying to make my divs "fluid" in a sense.
Example:
I have three divs and each has a class : <div col-12-xs col-6-md>
This means that on a medium and large screen div one and two would be side by side and div 3 would be below them.
<div class="container">
<div class="row">
<div class="col-sm-6 box">One</div>
<div class="col-sm-6 box">
Two
<br>
Two
<br>
Two
</div>
<div class="col-sm-6 box">Three</div>
</div>
</div>
So if this example code is used you would obviously be pushing the third div down while div two grows in height as more content is added.
My question is this.
Is there a way that I can make diff three stay below div one as div two grows in height but when the screen is smaller div two should still move beneath div one and above dif three.
Example of the problem
As you can see in the picture I would like to have div three below div one even if div two grows in height but on a small screen div two should move between div one and two.
Can this be done with bootstrap?
Make the second div to float:right. I have added pull-right class for that as you are using bootstrap
here is my fiddle https://jsfiddle.net/ze4g18a7/
div {
text-align:center;
font-size:20px;
}
.div1 {
height: 200px;
background-color: #ffe6ff;
}
.div2 {
height: 400px;
background-color: #ccfff5;
}
.div3 {
height: 200px;
background-color: #80dfff;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<div class="div1 col-xs-12 col-sm-6 col-md-6 col-lg-6">1</div>
<div class="div2 col-xs-12 col-sm-6 col-md-6 col-lg-6 pull-right">2</div>
<div class="div3 col-xs-12 col-sm-6 col-md-6 col-lg-6">3</div>
</div>
You could add a clearfix after the first 2 divs, like so:
<div class="container">
<div class="row">
<div class="col-sm-6 box">One</div>
<div class="col-sm-6 box">
Two
<br>
Two
<br>
Two
</div>
<div class="clearfix col-xs-12></div>
<div class="col-sm-6 box">Three</div>
</div>
</div>
This will cause the third div to always stay below the top two
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>