HTML / CSS : Creating and positionning 5 blocs - html

I am trying to positionning 5 blocs in my page.
I would like to have 3 columns in fact :
First column : Two blocs (Favorites and meetings)
Second column : (recents news and tweets)
Third column : Other favorites column
Like this :
But i have a problem for positionning the third column.
Here is my HTML code :
<div class="containerBloc" >
<div class="box-1">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu"><span id="textMenu">Favorites</span></div>
</div>
<div class="box-2">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_feed.png" id="imgIntoMenu"><span id="textMenu">Recent news</span></div>
</div>
<div class="box-5">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu"><span id="textMenu">Favorites</span></div>
</div>
<div class="box-3">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_calendar_month.png" id="imgIntoMenu"><span id="textMenu">Upcoming meetings</span></div>
</div>
<div class="box-4">
<div class="box-menu"><img src="src/ui_dashboard/img/ic_action_twitter.png" id="imgIntoMenu"><span id="textMenu">Tweets de</span></div>
</div>
</div>
And CSS :
.containerBloc {
max-width: 1200px;
margin: 0 auto;
overflow: hidden;
margin-top: 150px;
}
.box-1, .box-2, .box-3, .box-4 {
float: left;
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
}
.box-1, .box-2 {
height: 200px;
}
.box-1, .box-3 {
width: 30%;
}
.box-2, .box-4 {
width: 60%;
}
.box-5 {
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
float : right;
height : 100%;
width : 40%;
}
.box-menu {
background-color: #EFEFEF ;
height : 40px;
color : #B0B0B0;
border-bottom: 1px solid #B0B0B0;
}
#imgIntoMenu {
margin-left : 10px;
margin-top : 4px;
}
#textMenu {
margin-left: 10px;
position: absolute;
margin-top: 13px;
}
My complete code is here : http://jsfiddle.net/mzV85/
Thanks a lot for your help.

This FIDDLE should get you going.there is some tydying up to do in the CSS code.
The point is to Use Divs to wrap your columns. To set there added widths to 100% and to float them to the left.
HTML:
<div class="containerBloc">
<div class="col">
<div class="box-1">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu" /> <span id="textMenu">Favorites</span>
</div>
</div>
<div class="box-2">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_feed.png" id="imgIntoMenu" /> <span id="textMenu">Recent news</span>
</div>
</div>
</div>
<div class="col">
<div class="box-3">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_calendar_month.png" id="imgIntoMenu" /><span id="textMenu">Upcoming meetings</span>
</div>
</div>
<div class="box-4">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_twitter.png" id="imgIntoMenu" /><span id="textMenu">Tweets de #__Erwan</span>
</div>
</div>
</div>
<div class="col">
<div class="box-5">
<div class="box-menu">
<img src="src/ui_dashboard/img/ic_action_users.png" id="imgIntoMenu" /><span id="textMenu">Favorites</span>
</div>
</div>
</div>
</div>
CSS:
.col{
float:left;
width:33%;
margin:0;
padding:0;
}
.containerBloc {
max-width: 1200px;
margin: 0 auto;
overflow: hidden;
margin-top: 150px;
}
.box-1, .box-2, .box-3, .box-4 {
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
}
.box-1, .box-2 {
height: 200px;
}
.box-1, .box-3 {
width: 98%;
}
.box-2, .box-4 {
width: 98%;
}
.box-5 {
margin: 1%;
min-height: 150px;
box-sizing: border-box;
-moz-box-sizing: border-box;
background-color: #FFFFFF;
border: 1px solid #B0B0B0;
float : right;
height : 100%;
width : 98%;
}
.box-menu {
background-color: #EFEFEF;
height : 40px;
color : #B0B0B0;
border-bottom: 1px solid #B0B0B0;
}
#imgIntoMenu {
margin-left : 10px;
margin-top : 4px;
}
#textMenu {
margin-left: 10px;
position: absolute;
margin-top: 13px;
}

You should really be using a responsive grid system like Bootstrap.
However if I understand correctly you're just wanting to put together a three column layout, like this - http://jsfiddle.net/webbymatt/ngxA6/
<div class="container">
<div class="col-1">
<div class="child">
Favourites
</div>
<div class="child clearfix">
Meetings
</div>
</div>
<div class="col-2">
<div class="child">
Recent
</div>
<div class="child clearfix">
Tweets
</div>
</div>
<div class="col-3">
<div class="child">
Favourites
</div>
</div>
</div>

The layout is breaking because the percentage widths you are using add up to more than 100%. If you reduce the width of your columns it works.
http://jsfiddle.net/mzV85/15/
CSS:
.box-1, .box-3 {
width: 25%;
}
.box-2, .box-4 {
width: 50%;
}
.box-5 {
width : 19%;
}

Have Done a fiddle. Please check http://jsfiddle.net/mzV85/21/ . Please check the width of the containers properly.

Problem : your markup has box-1, box-2 and box-5 in one line.....calculate their combined width and it comes > 100%; that's why your third box is not aligning
see this demo http://jsfiddle.net/mzV85/10/ (aligned the box in one line,not did the complete designing)
.box-1, .box-2 {
height: 200px;
width:20%; /* do some changes here */
}
.box-1, .box-3 {
width: 30%;/* do some changes here */
}
Play around with the width and you will get it in one line when its combined width <=100%

Related

How to set vertical height in CSS?

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>

Alignment issue with child div inside the parent div

I have div(class name:xyz)to insert small 4 divs (class name:ax )in it.
I need to insert the first two divs vertically, the third one should come next to first one horizontally and the fourth one should come next to the third vertically.
But all the children are appearing vertically in side the parent.
.xyz {
max-height: 450px;
max-width: 500px;
}
.ax {
height: 200px;
width: 200px;
margin: 0 50px 25px 0;
background-color: #C0C0C0;
}
<div class="xyz">
<div class="ax"> </div>
<div class="ax"> </div>
<div class="ax"> </div>
<div class="ax"> </div>
</div>
You can use CSS3 Multiple column layout which in your case will be column-count: 2;, this property works in following browsers.
.xyz {
max-height: 450px;
max-width: 500px;
column-count: 2;
-webkit-column-count: 2;
}
.ax {
height: 200px;
width: 200px;
margin: 0 50px 25px 0;
background-color: #C0C0C0;
display:inline-block;
}
<div class="xyz">
<div class="ax">1</div>
<div class="ax">2</div>
<div class="ax">3</div>
<div class="ax">4</div>
</div>
.xyz {
max-height: 450px;
max-width: 500px;
}
.ax {
height: 200px;
width: 200px;
margin: 0 50px 25px 0;
background-color: #C0C0C0;
float: left;
}
<div class="xyz">
<div class="ax"> </div>
<div class="ax"> </div>
<div class="ax"> </div>
<div class="ax"> </div>
</div>
Like this?
.xyz {
max-height: 450px;
max-width: 500px;
}
.ax {
height: 200px;
width: 200px;
margin: 0 50px 25px 0;
background-color: #C0C0C0;
float:left;
}
<div class="xyz">
<div class="ax"> </div>
<div class="ax"> </div>
<div style="clear:both"></div>
<div class="ax"> </div>
<div class="ax"> </div>
</div>
I think you are looking for this one , try with snippet
.xyz {
max-height: 450px;
max-width: 500px;
margin-right: -25px; /* newly added */
margin-left: -25px; /* newly added */
}
.ax {
height: 200px;
width: 200px;
margin: 0 25px 25px 25px;
background-color: #C0C0C0;
float:left; /* newly added */
}
<div class="xyz">
<div class="ax">1 </div>
<div class="ax">2 </div>
<div class="ax">3 </div>
<div class="ax">4 </div>
</div>

Stacking Boxes in HTML and CSS

I wanted to create three boxes and align them properly. It would be two boxes in 1 row and a third box under the second box. The second and third box would have the height equal to the first box. You can visually see what I'm trying to do here: http://codepen.io/sibraza/pen/KMzwWR
Here is an example of what I'm trying to achieve:
Snippet:
.block {
float: left;
display: inline-block;
margin: auto;
width: 250px;
height: 200px;
border: 3px solid #73AD21;
padding: 10px;
margin-left: 300px;
margin-top: 200px;
}
.block2 {
float: left;
display: inline-block;
margin: auto;
width: 250px;
margin-top: 200px;
border: 3px solid #73AD21;
padding: 10px;
}
.block3 {
float: left;
margin: auto;
width: 250px;
height: 200px;
margin-top: 290px;
border: 3px solid #73AD21;
padding: 10px;
}
<div class="container-fluid">
<div class="row">
<div class="col-4-md text-center block">
<h2> Some Text </h2>
</div>
<div class="col-4-md text-center block2">
<h2> Other Text </h2>
</div>
<div class="col-4-md text-center block3">
<h2> More Text </h2>
</div>
</div>
</div>
Flexbox can do that with a wrapper for the right side divs
* {
box-sizing: border-box;
}
.row {
display: flex;
}
div {
border: 1px solid #73AD21;
}
.block {
height: 200px;
}
.row > div {
flex: 1;
}
.col-wrap {
display: flex;
flex-direction: column;
}
.col-wrap > div {
flex: 1;
}
<div class="container-fluid">
<div class="row">
<div class="col-4-md text-center block">
<h2> Some Text </h2>
</div>
<div class="col-wrap">
<div class="col-4-md text-center block2">
<h2> Other Text </h2>
</div>
<div class="col-4-md text-center block3">
<h2> More Text </h2>
</div>
</div>
</div>
</div>
Easiest way to sort this is to have the bigger div ont he let as is, and create a container Div for the two on the right. so the css would be somehting like this:
.block_on_the_left {
float:left;
width:50%;
}
#container_on_the_right {
float:left;
width:50%;
}
.block2 {
width:100%;
}
.block3 {
width:100%;
}
Your HTML would need to be:
<div class="block_on_the_left">
some stuff here for the left bit
</div>
<div id="container_on_the_right">
<div class=".block2">
some stuff
</div>
<div class=".block3">
some more stuff
</div>
</div>
The container will hold both the smaller divs inside it, and group them together.
Here is a simple solution using flex-box.
Hope this will help. Thanks :)
.row{
display: flex;
}
.block {
width: 250px;
height: 400px;
border: 3px solid red;
box-sizing: border-box;
}
.block2 {
width: 250px;
height: 200px;
border: 3px solid #73AD21;
box-sizing: border-box;
}
.block3 {
width: 250px;
height: 200px;
border: 3px solid blue;
box-sizing: border-box;
align-self: flex-end;
margin-left: -250px;
}
<div class="container-fluid">
<div class="row">
<div class="col-4-md text-center block">
<h2> Some Text </h2>
</div>
<div class="col-4-md text-center block2">
<h2> Other Text </h2>
</div>
<div class="col-4-md text-center block3">
<h2> More Text </h2>
</div>
</div>
</div>

Div width equal to gap between two other divs

I have several divs in a container, organized in a row.
$(document).ready(function() {
$('#swap').click(function() {
$('#container').find('div.blue').each(function() {
$(this).removeClass('blue');
$(this).addClass('green');
});
});
});
#container {
border: 1px solid black;
border-right: 0px;
width: 500px;
min-height: 40px;
}
#left {
float: left;
}
#right {
float: right;
}
.purple {
background-color: #9471AB;
width: 70px;
}
.red {
background-color: #D48A8A;
width: 40px;
}
.green {
background-color: #A4B995;
width: 50px;
}
.blue {
background-color: #95AEB9;
width: 75px;
}
.red,.green,.blue,.purple {
height: 40px;
float: left;
box-sizing: border-box;
border-right: 1px black solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="container">
<div id="left">
<div class="purple">
</div>
<div class="purple">
</div>
<div class="purple">
</div>
</div>
<div id="middle">
<div class="red">
</div>
</div>
<div id="right">
<div class="blue">
</div>
<div class="blue">
</div>
<div class="green">
</div>
</div>
</div>
<br/>
<button id="swap">Swap</button>
.purple, .blue, .green are defined widths, but not .red. For this example, I've given it a width.
I'd like .red to have a width equal to the gap between #left and #right. I could put it underneath all of them and make the width equal to container width, but I'm looking for something that's friendly with text.
I've put a button that changes all .blue to .green. .red should stretch its width accordingly so there's no gap. Some scenarios might have two .green and one .blue on the right, some might be three .blue or three .green., etc. It should be dynamic and not calculated against the width of other classes.
flexbox solution
$(document).ready(function() {
$('#swap').click(function() {
$('#container').find('div.blue').each(function() {
$(this).removeClass('blue');
$(this).addClass('green');
});
});
});
* {
box-sizing: border-box;
}
#container {
border: 1px solid black;
border-right: 0px;
width: 500px;
margin: 10p auto;
display: flex;
justify-content: space-between;
}
#left {
display: flex;
}
#middle {
display: flex;
flex:1;
}
#right {
display: flex;
}
.purple {
background-color: #9471AB;
width: 70px;
}
.red {
background-color: #D48A8A;
flex:1;
}
.green {
background-color: #A4B995;
width: 50px;
}
.blue {
background-color: #95AEB9;
width: 75px;
}
.red,.green,.blue,.purple {
height: 40px;
border-right: 1px black solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
<div id="left">
<div class="purple">
</div>
<div class="purple">
</div>
<div class="purple">
</div>
</div>
<div id="middle">
<div class="red">
</div>
</div>
<div id="right">
<div class="blue">
</div>
<div class="blue">
</div>
<div class="green">
</div>
</div>
</div>
<br/>
<button id="swap">Swap</button>
Update
http://jsfiddle.net/w4rxg7v3/1/
This approach lets you have dynamic widths of left and right, and middle fills in the rest.
<div class="middle">
<div class="left"></div>
<div class="right"></div>
<p>Content for Middle: cupiditate blanditiis dolorum natus!</p>
</div>
============================================================
http://jsfiddle.net/w4rxg7v3/
You can accomplish this using float and calc().
Make 1st div float:left, right div to float:right, then make middle one float either left or right. Then set its width to calc( 100% - sumofwidthothertwodivs)
body {
min-width: 500px;
}
.left,.middle,.right {
height: 80px;
}
.left {
background-color: blue;
width: 200px;
float: left;
}
.middle {
width: calc( 100% - 400px ) ;
float: right;
background-color: red;
}
.right {
background-color: green;
float: right;
width: 200px;
}

How to make arrange div containers in CSS?

So I have several div containers for my website, and they stack vertically as follows:
and I want it to look more like this:
My HTML looks like this:
<div id="main">
<div id="header">
</div>
<div id="content">
<div id="game" class="box">
<canvas data-processing-sources="hello-web.pde"></canvas>
</div>
<div id="desc_down"> <!-- Description and Downloads -->
<div id="desc" class="box"> <!-- Description -->
</div>
<div id="down"> <!-- Downloads -->
<div id="windows" class="box">
</div>
<div id="mac" class="box">
</div>
<div id="linux" class="box">
</div>
<div id="code" class="box">
</div>
<div id="info" class="box">
</div>
</div>
</div>
<div id="screenshots" class="box">
</div>
<div id="tech_about">
<div id="tech" class="box">
</div>
<div id="about" class="box">
</div>
</div>
</div>
</div>
<div>
and my CSS like this:
#main {
max-width: 1280px;
width: 90%;
margin: 0 auto;
background-color: #b0e0e6; /* all colours temp */
}
#header, #content, #game, #desc_down, #screenshots, #tech_about, #info {
width: 100%;
}
#desc {
width: 60%;
}
#down {
width: 40%;
}
#windows, #mac, #linux, #code {
width: 50%;
}
#about {
width: 45%;
}
#tech {
width: 50%;
}
.box {
background-color: #FFFFFF;
border: 5px solid;
border-color: #000000;
height: 200px;
-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */
}
The heights of these boxes can and will change. I want to know how to make my website look like how want it to. Thank you.
Make them all float:left or display:inline-block.
Or better use sth like Bootstrap Grid system
There are endless ways to position your content. Here is an example of what can be achieved using floats.
Have an example!
HTML
<div id="wrap">
<div id="header"></div>
<div id="paneOne"></div>
<div class="minPane"></div>
<div class="minPane"></div>
<div class="minPane"></div>
<div class="minPane"></div>
<div id="wideMinPane"></div>
<div id="afterMini"></div>
</div>
CSS
#wrap {
width: 800px;
margin: 0 auto;
}
#header {
height: 200px;
background: #F00;
}
#paneOne {
width: 400px;
height: 500px;
background: #000;
float: left;
}
.minPane {
float: left;
width: 198px;
height: 200px;
background: #FF0;
border: solid 1px #000;
}
#wideMinPane {
float: left;
background: #F00;
border: solid 1px #000;
height: 90px;
background: #FF0;
width: 398px;
}
#afterMini {
height: 300px;
background: #F00;
clear: left;
}
Its simple. Set the width of the container div (which encloses all these div blocks)to some value.
Then give float:left to all the inner divs.