I have bootstrap column arrangement as following and have few divs with different height inside the columns.
HERE IS THE CODEPEN
.column>div {
border: 1px solid #333;
background: #ddd;
color: white;
padding: 15px;
margin: 5px 0;
text-align: center;
font-size: 18px;
}
div#child-1 {
height: 150px;
}
div#child-2 {
height: 50px;
}
div#child-3 {
height: 50px
}
div#child-4 {
height: 100px;
}
div#child-5 {
height: 100px;
}
div#child-6 {
height: 150px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12 column">
<div id="child-1">1</div>
<div id="child-3">3</div>
<div id="child-5">5</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12 column">
<div id="child-2">2</div>
<div id="child-4">4</div>
<div id="child-6">6</div>
</div>
</div>
</div>
When it comes to mobile devices, I need to use col-xs-12 for each columns.
Now I need to have the following structure formed in the responsive #child-1, #child-2, #child-3, #child-4, #child-5, #child-6.
But for now I have the pattern mixed as #child-1, #child-3, #child-5, #child-2, #child-4, #child-6.
How can I swap these elements to the alignment that I wanted?
I think float can be helpful for such layout then on small device you can switch to flexbox (or even CSS-grid) and adjust the order. The main trick is to have all the elements inside one container so that you can easily handle them:
.container {
max-width:1124px;
margin:auto;
}
.column>div {
border: 1px solid #333;
background: #ddd;
color: white;
padding: 15px;
margin: 5px;
text-align: center;
font-size: 18px;
box-sizing:border-box;
width:calc(50% - 10px);
}
div#child-1 {
height: 150px;
float:left;
}
div#child-2 {
height: 50px;
float:right;
}
div#child-3 {
height: 50px;
float:left;
}
div#child-4 {
height: 100px;
float:right;
}
div#child-5 {
height: 100px;
float:left;
}
div#child-6 {
height: 150px;
float:right;
}
#media (max-width:767px) {
.container {
display:flex;
flex-direction:column;
}
.column > div {
width:auto;
}
#child-1 {order:1}
#child-2 {order:2}
#child-3 {order:3}
#child-4 {order:4}
#child-5 {order:5}
#child-6 {order:6}
}
<div class="container column">
<div id="child-1">1</div>
<div id="child-2">2</div>
<div id="child-4">4</div>
<div id="child-3">3</div>
<div id="child-6">6</div>
<div id="child-5">5</div>
</div>
Related
I need to give vertical height for the right element with full background. I tried by setting
height:100%;
max-height: 100%
but the element takes only content height
.full_container {
height: 350px;
border: 1px solid #ddd;
}
.pull-left {
float: left;
}
.width50 {
width: 50%;
}
.inline_height {
color: #fff;
padding: 10px;
background: #333;
}
.height100 {
padding: 10px;
height: 100%;
max-height: 100%;
background: #e8e8e8;
}
<div class="full_container">
<div class="clearfix">
<div class="pull-left width50">
<div class="inline_height">
Content height only
</div>
</div>
<div class="pull-left width50">
<div class="height100">
<div>I need to show this div element height to 100%</div>
</div>
</div>
</div>
</div>
Try giving the .clearfix class a display:flex and height:100%
.clearfix {
display: flex;
height: 100%;
}
Example below
.full_container {
height: 350px;
border: 1px solid #ddd;
}
.pull-left {
float: left;
}
.width50 {
width: 50%;
}
.inline_height {
color: #fff;
padding: 10px;
background: #333;
}
.height100 {
padding: 10px;
height: 100%;
max-height: 100%;
background: #e8e8e8;
}
.clearfix {
display: flex;
height: 100%;
}
<div class="full_container">
<div class="clearfix">
<div class="pull-left width50">
<div class="inline_height">
Content height only
</div>
</div>
<div class="pull-left width50">
<div class="height100">
<div>I need to show this div element height to 100%</div>
</div>
</div>
</div>
</div>
See this:
I have added display: flex for .full_container
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.full_container {
height: 350px;
border: 1px solid #ddd;
display: flex;
}
.pull-left {
float: left;
}
.width50 {
width: 50%;
}
.inline_height {
color: #fff;
padding: 10px;
background: #333;
}
.height100 {
padding: 10px;
height: 100%;
max-height: 100%;
background: #e8e8e8;
}
<div class="full_container">
<div class="pull-left width50">
<div class="inline_height">
Content height only
</div>
</div>
<div class="pull-left width50">
<div class="height100">
<div>I need to show this div element height to 100%</div>
</div>
</div>
</div>
I have three divs with equal width and the third div to expand to full width below a breakpoint (991px to be exact) and all the divs stack upon each other when browser width is below 767px, and now i want equal margins(between divs & at the edges) so please let me know a way out. And I want to achieve this without any frameworks i,e just with the help of css.
Here's the code:
* {
box-sizing: border-box;
}
h1 {
margin: 25px;
text-align: center;
}
div[class|=col] {
position: relative;
margin-bottom: 10px;
border: 1px solid black;
}
html,
body {
margin: 15px;
}
.title {
border-left: 1px solid black;
border-bottom: 1px solid black;
width: 25%;
position: absolute;
top: 0px;
right: 0px;
color: black;
text-align: center;
}
#Title1 {
background-color: orange;
}
#Title2 {
background-color: white;
}
#Title3 {
background-color: green;
}
p {
background-color: gray;
width: 100%;
margin: 0px;
padding-left: 10px;
padding-right: 10px;
padding-top: 25px;
font-family: Helvetica;
color: black;
}
.row {
width: 100%;
}
<div class="row">
<div class="col-lg-4 col-md-6 ">
<section id="Title1" class="title">Chicken</section>
<p>Some text</p>
</div>
<div class="col-lg-4 col-md-6">
<section id="Title2" class="title">Beef</section>
<p>Some text</p>
</div>
<div class="col-lg-4 col-md-12">
<section id="Title3" class="title">Sushi</section>
<p>Some text</p>
</div>
</div>
Add classes to the 3 div's: div-1, div-2, div-3
#media only screen and (max-width:766px) {
.div-1.div-2.div-3 {
margin-bottom: 10px;
}
}
Like this you can add margin's for a particular resolution as per your requirement.
I'm having this HTML/CSS code:
.container
{
max-width: 900px;
margin: 0 auto;
margin-top: 30px;
}
.divisions
{
border: 1px solid Black;
}
.Fisrt-Line
{
height: 180px;
}
.First
{
background-color: Green;
width: 32.2%;
}
.Second
{
width: 65%;
background-color: White;
margin-left: 20px;
}
.Second-Line
{
margin-top: 20px;
background-color: Blue;
float: left;
width: 100%;
height: 180px;
}
.Third-Line
{
height: 180px;
width: 31.6%;
float: left;
margin-top: 20px;
}
.Third-2
{
margin-left: 20px;
background-color: Red;
}
.Third-3
{
margin-left: 20px;
}
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link href="Styles/StyleSheet.css" rel="stylesheet" />
</head>
<body class="container">
<div class=" divisions Fisrt-Line First">
1</div>
<div class=" divisions Fisrt-Line Second">
2</div>
<div class="divisions Second-Line">
3
</div>
<div class="divisions Third-Line">
4
</div>
<div class="divisions Third-Line Third-2">
5
</div>
<div class="divisions Third-Line Third-3">
6
</div>
</body>
</html>
When I minimize the browser the second div and also the last div jump to next line. but I don't want that.
How should I edit the code so that those divisions just become smaller not jump to next line?
Do you mind to add additional wrappers for rows? if not please take a look here http://jsfiddle.net/ch0L9fy8/2/
Main update here beside row wrappers:
.divisions-line {
width: 100%;
}
.divisions {
box-sizing: border-box;
border: 1px solid Black;
}
I'm trying to put 3 divs(with different widths respectively : 10%,70% & 20%) in the same row but the middle one always go full width of the page.
Here is my code:
#left-bar {
width: 10%;
background-color: #FF0000;
}
#middle-bar {
width: 70%;
background-color: #6600FF;
}
#right-bar {
width: 20%;
background-color: #99FF99;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
By default div is a block level element that's why they aren't in the same row.
You have a few options to fix this:
option with CSS flexbox:
.row {
display: flex;
width: 100%
}
.row>div {
/*demo purposes */
height: 30px;
}
#left-bar {
flex: 0 10%;
background-color: #F00;
}
#middle-bar {
flex: 1;
background-color: #60F;
}
#right-bar {
flex: 0 20%;
background-color: #9F9;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
(old options)
option with display:inline-block
.row {
/*fix inline-block gap*/
font-size: 0;
}
.row>div {
display: inline-block;
/*demo purposes */
height: 30px;
}
#left-bar {
width: 10%;
background-color: #F00;
}
#middle-bar {
width: 70%;
background-color: #60F;
}
#right-bar {
width: 20%;
background-color: #9F9;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
option with display:table-[cell]
.row {
display: table;
width: 100%
}
.row>div {
display: table-cell;
/*demo purposes */
height: 30px;
}
#left-bar {
width: 10%;
background-color: #F00;
}
#middle-bar {
width: 70%;
background-color: #60F;
}
#right-bar {
width: 20%;
background-color: #9F9;
}
<div class="row">
<div id="left-bar"></div>
<div id="middle-bar"></div>
<div id="right-bar"></div>
</div>
The table-cell option actually doesn't work in some internet explorer versions. But the same result can be achieved with the property float:
#left-bar{
width:10%;
background-color: #FF0000;
}
#middle-bar{
width:70%;
background-color: #6600FF;
}
#right-bar{
width:20%;
background-color: #99FF99;
}
.row > div {float:left;}
<div class="row">
<div id="left-bar">a</div>
<div id="middle-bar">b</div>
<div id="right-bar">c</div>
</div>
#left-bar{
width:10%;
background-color: #FF0000;
float:left;
}
#middle-bar{
width:70%;
background-color: #6600FF;
float:left;
}
#right-bar{
width:20%;
background-color: #99FF99;
float:left;
}
If that doesn't work, please provide more html and css because the problem will be somewhere else. Also, verify that you have heights set for your divs.
I have been created the web page using html and css.
I have been created two products in one column.
I need to add vertical hr line between these two products.
For that i did,
Html:
<div class="headerDivider"></div>
Css:
.headerDivider {
border-right:1px solid #16222c;
height:400px;
margin-right: 458px;
overflow:hidden;
}
It doesn't work correctly, Here is my jsfiddle: http://jsfiddle.net/22z6vjrx/
Can anyone please help me to fix this,
Thanks in advance .....
You have to float all of divs (or inline-block display). But I prefer to add vertical line as border on right for elements:
.product {
float: left;
width: 100px;
height: 200px;
margin-bottom: 5px;
}
.clear {
clear: both;
}
.first {
background-color: #eee;
}
.product:not(:last-child) {
border-right: 1px solid black;
}
.second {
background-color: #ddd;
}
.third {
background-color: #dfd;
}
.fourth {
background-color: #ddf;
}
<div class='row'>
<div class='clear'></div>
<div class="product first"></div>
<div class="product second"></div>
</div>
<div class='row'>
<div class='clear'></div>
<div class="product third"></div>
<div class="product fourth"></div>
</div>
Updated version
Add box-sizing: border-box; to include border and padding to element width (otherwise with will be too big as it will be width + border-width * 2 + padding * 2). Also make sure you have floated products divs as well as vertical hr:
.product,
.vhr {
box-sizing: border-box;
}
.product {
float: left;
width: 49%;
height: 200px;
margin-bottom: 5px;
}
.first {
background-color: #eee;
}
.second {
background-color: #ddd;
}
.vhr {
float: left;
border-left: 1px solid black;
height: 200px;
width: 1%;
margin-left: 1%;
}
<div class="product first"></div>
<div class="vhr"></div>
<div class="product second"></div>