Two Divs next to each other, that then stack with responsive change - css

I'm trying to achieve something that I am sure should be easier than I am making it!
I am using the Skeleton responsive framework, and have been fine up until now.
Here is a diagram of what I want to achieve.
This will be placed within a column. Once that columns reduces in size, I would like it to stack the divs as per the second example in the diagram. I've tried a few different ways, but keep getting it wrong.
I am pretty new to HTML/CSS so any help is appreciated! Many thanks!

You can use CSS3 media query for this. Write like this:
CSS
.wrapper {
border : 2px solid #000;
overflow:hidden;
}
.wrapper div {
min-height: 200px;
padding: 10px;
}
#one {
background-color: gray;
float:left;
margin-right:20px;
width:140px;
border-right:2px solid #000;
}
#two {
background-color: white;
overflow:hidden;
margin:10px;
border:2px dashed #ccc;
min-height:170px;
}
#media screen and (max-width: 400px) {
#one {
float: none;
margin-right:0;
width:auto;
border:0;
border-bottom:2px solid #000;
}
}
HTML
<div class="wrapper">
<div id="one">one</div>
<div id="two">two</div>
</div>
Check this for more http://jsfiddle.net/cUCvY/1/

today this kind of thing can be done by using display:flex;
https://jsfiddle.net/suunyz3e/1435/
html:
<div class="container flex-direction">
<div class="div1">
<span>Div One</span>
</div>
<div class="div2">
<span>Div Two</span>
</div>
</div>
css:
.container{
display:inline-flex;
flex-wrap:wrap;
border:1px solid black;
}
.flex-direction{
flex-direction:row;
}
.div1{
border-right:1px solid black;
background-color:#727272;
width:165px;
height:132px;
}
.div2{
background-color:#fff;
width:314px;
height:132px;
}
span{
font-size:16px;
font-weight:bold;
display: block;
line-height: 132px;
text-align: center;
}
#media screen and (max-width: 500px) {
.flex-direction{
flex-direction:column;
}
.div1{
width:202px;
height:131px;
border-right:none;
border-bottom:1px solid black;
}
.div2{
width:202px;
height:107px;
}
.div2 span{
line-height:107px;
}
}

Floating div's will help what your trying to achieve.
Example
HTML
<div class="container">
<div class="content1 content">
</div>
<div class="content2 content">
</div>
</div>
CSS
.container{
width:100%;
height:200px;
background-color:grey;
}
.content{
float:left;
height:30px;
}
.content1{
background-color:blue;
width:300px;
}
.content2{
width:200px;
background-color:green;
}
Zoom in the page to see the effects.
Hope it helps.

Better late than never!
https://getbootstrap.com/docs/4.5/layout/grid/
<div class="container">
<div class="row">
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
<div class="col-sm">
One of three columns
</div>
</div>
</div>

With a mediaquery based on a min-width you could achieve something like http://jsbin.com/aruyiq/1/edit
CSS
.wrapper {
border : 2px dotted #ccc; padding: 2px;
}
.wrapper div {
width: 100%;
min-height: 200px;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#one { background-color: gray; }
#two { background-color: white; }
#media screen and (min-width: 600px) {
.wrapper {
height: auto; overflow: hidden; // clearing
}
#one { width: 200px; float: left; }
#two { margin-left: 200px; }
}
In my example the breakpoint is 600px but you could adapt it to your needs.

Do like this:
HTML
<div class="parent">
<div class="child"></div>
<div class="child"></div>
</div>
CSS
.parent{
width: 400px;
background: red;
}
.child{
float: left;
width:200px;
background:green;
height: 100px;
}
This is working jsfiddle. Change child width to more then 200px and they will stack.

Related

Css form with two div<> inside

I have 2 div<> that I would like to be next to eachother. They are inside of a form<>. The one I have on the left won't float all the way up. It seems that my First Div keeps blocking it. I have resized it multiple times and It still doesn't work. Here is my Css code and as you can see there is not much to it. I also have no inline styling. My first Div is called ContactInput and my second Div is called invisible
#body {
border: 1px double black;
}
#checkout { //this is just a head at the top
text-align:left;
border-bottom: 1px solid black;
}
#contactInput{
clear:right;
padding:.5em;
}
#invisible{
float:right;
padding:.5em;
}
Like this?
#contact {
width: 50%;
padding:.5em;
background: blue;
float: left;
box-sizing: border-box;
}
#invisible {
width: 50%;
padding:.5em;
background: red;
float: left;
box-sizing: border-box;
}
<div id="contact">
</div>
<div id="invisible">
</div>
I recommend flex instead of float
.wrap {
display: flex;
}
#contact {
flex: 1;
padding:.5em;
background: blue;
}
#invisible {
flex: 1;
padding:.5em;
background: red;
}
<div class="wrap">
<div id="contact">
</div>
<div id="invisible">
</div>
</div>

How to stop content keeping in line in embedded table-cell in CSS?

I want to use the table-cell to make a two-col layout. the content in the inner table has no relationship with the outer table.
My problem is the menu in the left-col will keep in line with the content in the inner- table-cell(the inner-left-head and inner-right-head). How can I stop it?
.wrap {border: 1px solid #ddd;}
.left-col,
.right-col
{
display:table-cell;
}
.left-col {
border-right: 1px solid #ddd;
width:17.5%;
max-width:209px;
}
.right-col {width:2000px;}
.right-col-main {
margin: 30px;
border: 1px solid #ddd;
}
.inner-left-col,
.inner-right-col {
display: table-cell;
height:300px;
}
.inner-left-col {
width:100px;
border-right: 1px solid #ddd;
}
.inner-right-col {
width: 500px;
}
.inner-left-head,
.inner-right-head {
height:48px;
line-height:48px;
border-bottom: 1px solid #ddd;
}
<div class="wrap">
<div class="left-col">
<dl>
<dt>menu<dt>
<dd>sub1<dd>
<dd>sub2<dd>
<dd>sub3<dd>
</dl>
</div>
<div class="right-col">
<div class="right-col-main">
<div class="inner-left-col">
<div class="inner-left-head">left head</div>
<div class="inner-left-body">left body</div>
</div>
<div class="inner-right-col">
<div class="inner-right-head">right head</div>
<div class="inner-right-body">right body</div>
</div>
</div>
</div>
</div>
I tried use table-row to wrap the table-cell but I can't see any difference.
Thanks for editing. It's starting to become clear now. You want to be able to scroll the right column while keeping the left column in sight. Then my question is, why did you make this table layout?
I think you're looking for position: fixed to fixate the left column to the top left corner. You can position the right column by just giving it a left margin.
So the styling for the left and right columns becomes:
.left-col {
position: fixed;
width: 17.5%;
top: 0;
left: 0;
}
.right-col
{
margin-left: 17.5%; /* Same or larger as width of left colum */
height: 2000px; /* Force some height to see the effect.
}
.wrap {border: 1px solid #ddd;}
.left-col {
position: fixed;
width: 17.5%;
top: 0;
left: 0;
}
.right-col
{
margin-left: 17.5%; /* Same or larger as width of left colum */
height: 2000px; /* Force some height to see the effect.
}
.right-col-main {
margin: 30px;
border: 1px solid #ddd;
}
.inner-left-col,
.inner-right-col {
display: table-cell;
height:300px;
}
.inner-left-col {
width:100px;
border-right: 1px solid #ddd;
}
.inner-right-col {
width: 500px;
}
.inner-left-head,
.inner-right-head {
height:48px;
line-height:48px;
border-bottom: 1px solid #ddd;
}
<div class="wrap">
<div class="left-col">
<dl>
<dt>menu<dt>
<dd>sub1<dd>
<dd>sub2<dd>
<dd>sub3<dd>
</dl>
</div>
<div class="right-col">
<div class="right-col-main">
<div class="inner-left-col">
<div class="inner-left-head">left head</div>
<div class="inner-left-body">left body</div>
</div>
<div class="inner-right-col">
<div class="inner-right-head">right head</div>
<div class="inner-right-body">right body</div>
</div>
</div>
</div>
</div>
Instead of using table-cells you could use floats. Combined with relative width settings you will furthermore have a more responsive solution.
This is just one example how it could be working:
.left-col,
.right-col {
float:left;
}
.left-col {
background:#abc;
width:17.5%;
}
.right-col {
background:#aed;
width:82.5%;
}
.right-col-main {
margin-top:40px;
}
.inner-left-col,
.inner-right-col {
float:left;
}
.inner-left-col {
width:20%;
}
.inner-right-col {
width:80%;
}
http://jsfiddle.net/xn0zuo7h/

Trying to create a flexible 3 button footer

Here is my fiddle
http://jsfiddle.net/8BJ94/68/
I need the buttons to be positioned centrally with a bit of padding around each one in the footer.
I've very close but the buttons seems to be overflowing off the bottom of the page?
html, body {
height:100%;
width:100%;
margin:0;
}
div#footer{
width:100%;
height:10%;
bottom:0;
top:90%;
left:0;
background-color:#2A2A2A;
position:fixed;
display:table-cell;
vertical-align:middle;
}
#button {
height : 90%;
width : 30%;
background-color : #FFFFFF;
margin:1.666%;
text-align:center;
float:left;
-webkit-border-radius: 1em;
-moz-border-radius: 1em;
border-radius: 1em;
}
#button:before {
content:'';
height:10%;
vertical-align:middle;
display:inline-block;
}
<div id="footer">
<div id="button">button text</div>
<div id="button">button text</div>
<div id="button">button text</div>
</div>
I have changed a lot of your css, this is what I have now:
http://jsfiddle.net/wf_4/8BJ94/78/
html, body {
height:100%;
width:100%;
margin:0;
}
html {
display:table;
}
body {
display:table-cell;
vertical-align:middle;
background:#48a;
text-align:center;
}
div#footer {
width:100%;
height:10%;
min-height:40px;
bottom:0;
left:0;
background-color:#2A2A2A;
position:fixed;
padding:8px;
display:table;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.button {
height : 50%;
width : 30%;
background-color : #FFFFFF;
margin:auto 2%;
display:table-cell;
-webkit-border-radius: 1em;
-moz-border-radius: 1em;
border-radius: 1em;
}
.button:before {
content:'';
height:100%;
vertical-align:middle;
display:inline-block;
}
.buttonGap {
height:50%;
width:1%;
display:inline-block;
}
and HTML:
<div id="footer">
<div class="button">button text</div>
<div class="buttonGap"></div>
<div class="button">button text</div>
<div class="buttonGap"></div>
<div class="button">button text</div>
</div>
I think that's what you need:
http://jsfiddle.net/e2262/1/
What was frorcing your footer to don't be elastic vertical (in height was)
div#footer {
height:10%;
top:90%;
}
SO i get ride of those 2 attribute in the CSS. Now it's anchored to the bottom and as the buttons grow the footer is able to grow in height ;)
Note: never use multiple elements with the CSS id attribute. I swapped with CSS classes
Just set the height of the button class to smaller, like this (note: I changed the button id's into classes, as id's should be unique - also pointed out by one of the commenters):
.button {
height : 60%; // <-- changed this
width : 30%;
background-color : #FFFFFF;
margin:1.666%;
text-align:center;
float:left;
-webkit-border-radius: 1em;
-moz-border-radius: 1em;
border-radius: 1em;
}
Fiddle here
I've updated my solution using flex-box:
HTML:
<div id="footer">
<div class="button">button text</div>
<div class="button">button text</div>
<div class="button">button text</div>
</div>
CSS:
div#footer{
position:fixed;
height: 10%;
bottom:0;
left:0;
right:0;
background-color:#2A2A2A;
padding:0;
margin:0;
text-align:center;
display: flex;
justify-content: space-around;
align-items: center;
}
#footer .button {
display: inline-block;
background-color : #FFFFFF;
-webkit-border-radius: 1em;
-moz-border-radius: 1em;
border-radius: 1em;
width: 30%;
height: 80%;
line-height: 25px;
}
JSFiddle

div layout as columns

i have the following code:
see in http://jsfiddle.net/bniya_dev/SYPNC/2/
<div>
<div id="mainHeader">
<div id="details1">
<span>details1</span>
</div>
<div id="details2">
<span>details2</span>
</div>
</div>
<div id="header">
<span>header </span>
</div>
</div>
css
div#details1
{
float:left; width:100px;
}
div#details2
{
float:right;
}
I want it to look like the following picture:
What style I should set?
I want it to work in all browsers even mobile browsers
http://jsfiddle.net/bniya_dev/SYPNC/2/
Try this:
You need to clear floats before header.
.clr{clear:both;}
DEMO
* {
margin: 0;
font-family: Arial ;
font-size: 35px;
line-height: 65px;
}
div#mainHeader {
width: 777px;
height: 65px;
background-color: aqua;
text-align: right;
}
div#details1 {
width: 620px;
height: 65px;
background-color: #ED1C24;
float: left;
}
div#details2 {
width: 157px;
height: 65px;
background-color: #22B14C;
float: left;
text-align: center;
}
div#header {
text-align: left;
}
This is the Demo
Maybe you should change the font by yourself (*^__^*)...
Try this one:
http://jsfiddle.net/SYPNC/9/
This should match your requirements. You can still adjust the width of your header1/header2
Give width for below in percentage according to your requirement
div#details1
{
float:left; width:90%;
}
Your html,css both should be change like bellow
HTML
<div id="details1"> <span>details1</span>
</div>
<div id="details2"> <span>details2</span>
</div>
<div id="header"> <span>header </span>
</div>
CSS
body{
width:500px;
}
#details1 {
float:left;
width:300px;
height:50px;
background-color:red;
}
#details2 {
float:right;
width:200px;
height:50px;
background-color:green;
}
DEMO
Try this:
div#details1
{
float:left;
background: red;
width: 90%;
text-align: right;
}
div#details2
{
float:right;
background: green;
width: 10%;
}
#header{
clear: both;
}
demo
But better way to markup like this.....
<div id="mainHeader">
<div id="details">
<span class="one">detail1</span>
<span class="two">detail2</span>
</div>
Then you can float: right; to #details

How to make a 3 column layout fill 100% width using pixel metric on 2 columns?

jsFiddle:
How do I make div2 + Button2 fill the rest of the window width if I use pixel metric on column 1 and 3?
I'll use that to format a form making a textbox to change the size as two other fields are fixed.
Thank you.
CSS
td { border:solid 1px #000; float:left; }
#div1 { width:100px; border:solid 1px #000; float:left; }
#div2 { border:solid 1px #000; float:left; }
#div3 { width:100px; border:solid 1px #000; float:right; }
#Button1 { width:100% }
#Button2 { width:100% }
#Button3 { width:100% }
HTML
<div id="div1">
<button id="Button1">Button 1</button>
</div>
<div id="div2">
<button id="Button2">Button 2</button>
</div>
<div id="div3">
<button id="Button3">Button 3</button>
</div>
Another solution is moving the second DIV to the bottom and applying margins on it without float: http://jsfiddle.net/xC7uZ/6/
As far as I know, there are only two ways of doing this:
Using tables - most people do not like this idea. I for one, think it's fine for overall layout as long as you don't go overboard with nested tables and stuff. Kalle's answer covers this option
Using absolute positioning specifying all four corners. I only recently discovered this method and it works beautifully. It works in all major browsers.
Something like this:
#div1 { position:absolute; left: 0px; width: 100px; border:solid 1px #000; }
#div2 { position:absolute; left: 100px; right: 100px; border:solid 1px #000; }
#div3 { position:absolute; right: 0px; width:100px; border:solid 1px #000; float:right; }
Here is one to make you guys think :)
<div class="maincontainer">
<div class="column01">
<div class="restraint">
<p>Left column</p>
</div>
</div>
<div class="column03">
<div class="restraint">
<p>Right column</p>
</div>
</div>
<div class="column02">
<div class="restraint">
<p>Middle column</p>
</div>
</div>
</div>
and the CSS:
.maincontainer {
position:relative;
overflow:hidden;
}
.maincontainer .column01 {
float:left;
}
.maincontainer .column01 .restraint,.maincontainer .column03 .restraint {
width:200px;
}
.maincontainer .column03 {
float:right;
}
.maincontainer .column02 {
overflow:hidden;
}
.maincontainer .column02 .restraint {
width:100%;
}
* html .maincontainer .column02 {
display:inline-block;
}
I will get hammered for using <table>, but this is the most flexible and crossbrowser method. It works in ie5 ^^
http://jsfiddle.net/hobobne/24urb/
En este ejemplo vemos como poner tres columnas, de las cuales, dos tienen tamaƱo fijo.
Three columns and one column with 100% and two columns with fixed width.
jsfiddle
CSS
div, span, label, li, ul
{
box-sizing: border-box;
-ms-box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.cabecera
{
top:0px;
left:0px;
width:100%;
height: 100px;
display: table;
position: absolute;
border:1px solid orange;
}
.row
{
width:100%;
display: table-row;
}
.column_izq
{
width:60px;
height:100%;
display: table-cell;
white-space: nowrap;
vertical-align: middle;
border:1px solid black;
}
.column_izq .icono
{
width: 100%;
text-align: center;
border:1px solid red;
}
.column_center
{
width: 100%;
min-width:60px;
text-align:center;
display: table-cell;
vertical-align: middle;
border:1px solid black;
}
.column_der
{
width:60px;
height:100%;
display: table-cell;
white-space: nowrap;
vertical-align: middle;
border:1px solid black;
}
.column_der .logo
{
width: 100%;
text-align: center;
border:1px solid red;
}

Resources