Placing divs side by side, but not in line - html

Consider the follwoing html code:
<h3>CPU Plot </h3>
<div id="CPU1"></div>
<h3>CPU Plot </h3>
<div id="CPU2"></div>
<h3>CPU Plot </h3>
<div id="CPU3"></div>
<h3>CPU Plot </h3>
<div id="CPU4"></div>
CSS goes like this:
#CPU1{
width:600px;
height:300px;
margin-top: 20px;
float:left;
}
#CPU2{
width:600px;
height:300px;
margin-top: 20px;
float:right;
}
#CPU3{
width:600px;
height:300px;
margin-top: 20px;
float:left;
}
#CPU4{
width:600px;
height:300px;
margin-top: 20px;
float:right;
}
I need to place all the four divs side by side, i.e. CPU1 and CPU2, beside each other and in the next line CPU3 and CPU4 (beside each other).
But it is not organised. My CPU1 tag is not inline with CPU2 tag, but when I remove the <h3> tag then all the divs are inline.
How can I have the title on the div tags?
An image for your reference. Click Here
I need this but with Title: Required

You should add the inside the DIV. Such as:
<div id="CPU1">
<h3>CPU Plot </h3>
<div class="add_graph_here"></div>
</div>
<div id="CPU2">
<h3>CPU Plot </h3>
<div class="add_graph_here"></div>
</div>
<div id="CPU3">
<h3>CPU Plot </h3>
<div class="add_graph_here"></div>
</div>
<div id="CPU4">
<h3>CPU Plot </h3>
<div class="add_graph_here"></div>
</div>
However, if your browsers width is wide enough (+1800px) the boxes will be plaxed incorrectly (according to your expectations).
For this reason, add in the CSS:
#CPU1{
width:50%;
height:300px;
margin-top: 20px;
float:left;
}
#CPU2{
width:50%;
height:300px;
margin-top: 20px;
float:right;
}
#CPU3{
width:50%;
height:300px;
margin-top: 20px;
float:left;
}
#CPU4{
width:50%;
height:300px;
margin-top: 20px;
float:right;
}
.add_graph_here { /*this represents your graph*/
height: 200px;
width: 200px;
background: #DDD;
border: 4px solid #ABABAB;
}
DEMO

Wrap divs in rows like
<div class="wrapper">
<div class="row">
<div id="CPU1"></div>
<div id="CPU2"></div>
</div>
<div class="row">
<div id="CPU3"></div>
<div id="CPU4"></div>
</div>
</wrapper>
give all CPU divs
float: left
and for row
.row {
float: left;
}
and for wrapper
.wrapper {
with: 1200px;
}

you can use float here. Take a look at this click me

You need to wrap your blocks and add "clear: left" to third block
HTML:
<div id="CPU1">
<h3>CPU Plot </h3>
<div></div>
</div>
<div id="CPU2">
<h3>CPU Plot </h3>
<div></div>
</div>
<div id="CPU3">
<h3>CPU Plot </h3>
<div></div>
</div>
<div id="CPU4">
<h3>CPU Plot </h3>
<div></div>
</div>
CSS:
#CPU1{
width:600px;
height:300px;
margin-top: 20px;
float: left;
}
#CPU2{
width:600px;
height:300px;
margin-top: 20px;
float: left;
}
#CPU3{
width:600px;
height:300px;
margin-top: 20px;
float: left;
clear: left;
}
#CPU4{
width:600px;
height:300px;
margin-top: 20px;
float: left;
}
then add your content to empty div's

<div id="CPU1" style=" height:400px;">
<h3>CPU Plot </h3>
<div id="CPU1" style="border:1px solid;"></div>
</div>
<div id="CPU2" style=" height:400px;">
<h3>CPU Plot </h3>
<div id="CPU2" style="border:1px solid;"></div></div>
<div id="CPU3" style=" height:400px;">
<h3>CPU Plot </h3>
<div id="CPU3" style="border:1px solid;"></div>
</div>
<div id="CPU4" style=" height:400px;">
<h3>CPU Plot </h3>
<div id="CPU4" style="border:1px solid;"></div>
</div>
just for example style according to your requirement.

I think this may help you:
HTML:
<div class="row">
<div id="CPU1">
<h3>CPU Plot </h3>
cpu1
</div>
<div id="CPU2">
<h3>CPU Plot </h3>
cpu2
</div></div>
<div class="row">
<div id="CPU3">
<h3>CPU Plot </h3>
cpu3
</div>
<div id="CPU4">
<h3>CPU Plot </h3>
cpu4
</div></div>
CSS:
#CPU1{
width:100px;
height:100px;
float:left;
display: inline-block;
}
#CPU2{
width:100px;
height:100px;
float:right;
display: inline-block;
}
#CPU3{
width:100px;
height:100px;
float:left;
display: inline-block;
}
#CPU4{
width:100px;
height:100px;
float:right;
display: inline-block;
}
.row{
width:300px;
clear:left;
}
http://jsfiddle.net/htevn7Ln/2/
You can also remove container rows and add "clear:left" to #CPU3.

Related

How to design a group of object

I want to make a group of buttons or spans that always fit in 6 places of screen (sorry I draw it not really straight). Thanks for your helping first.
.row__main{
max-width:280px;
margin:0 auto;
content:"";
display: block;
clear:both;
height:110px;
padding:0 15px 0 15px;
border: 1px solid black;
}
[class^="col-"]{
float:left;
}
[class^="col-"]:not(:last-child){
margin-right: 60px;
}
.col-1-of-3{
margin-top:23px;
width:calc((100% - 2*#{60px})/3);
}
<div class="row__main">
<div class="row-1">
<div class="col-1-of-3"><button>button</button></div>
<div class="col-1-of-3"><button>button</button></div>
<div class="col-1-of-3"><button>button</button></div>
</div>
<div class="row-1">
<div class="col-1-of-3"><button>button</button></div>
<div class="col-1-of-3"><button>button</button></div>
<div class="col-1-of-3"><button>button</button></div>
</div>
</div>

Vertically aligning selected div

Currently, my div content is in horizontal style, I want to make the another div content to be position vertically. For my case i want to vertically align my content1 element
This is how i want the css to look like
This is my html code:
<div id="binder">
<div id="content">
<div>
<h1>Title</h1>
</div>
<br/>
<div id="map">
</div>
</div>
<div id="content1">
</div>
<div id="sidebar">
</div>
</div>
This the css code:
#binder{
display:-webkit-box;
-webkit-box-orient:horizontal;
}
#content{
font:14px Calibri;
border:1px solid #3EA99F;
-webkit-box-flex:1;
margin:20px;
padding:20px;
}
#sideBar{
border:1px solid #3EA99F;
width:450px;
margin:20px;
padding:30px;
background:#3EA99F;
}
How to do it?
Eventually you can do it without using flexbox too.
Code example:
*{
box-sizing:border-box;
margin:0;
padding:0;
}
.content-wrapper,
#sidebar{
float: left;
}
.content-wrapper{
width:70%;
}
#content,
#content1,
#sidebar {
border: 1px solid red;
}
#sidebar {
width: 30%;
}
<div id="binder">
<div class="content-wrapper">
<div id="content">
<div>
<h1>Content div</h1>
</div>
<br/>
<div id="map">
</div>
</div>
<div id="content1">
<h3>
Content1 div
</h3>
</div>
</div>
<div id="sidebar">
<h3>
Sidebar div
</h3>
</div>
</div>
Notes
I added a .container-wrapper div as parent of both #content and #content1
I placed .container-wrapper and #sidebar next to each other with float:left
In this case the height of the containers is set automatically based on their content, but if you want you can specify a fixed value adding a height:..px to the corresponding class/id
change
#binder{
display:-webkit-box;
-webkit-box-orient:horizontal;
}
to
#binder{
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
as the explanation is not much enough, please check the JsFiddle and please explain if it is not as you expected
EDIT:
Thank you for providing the images.
change the html into
<div id="binder">
<div class="content-wrapper">
<div id="content">
<div>
<h1>Title</h1>
</div>
<br/>
<div id="map">
</div>
</div>
<div id="content1">
CONTENT 1
</div>
</div>
<div id="sidebar">
SIDEBAR
</div>
change the css to
#binder{
display:flex;
flex-direction: row;
}
.content-wrapper{
display:flex;
flex-direction: column;
}
#sidebar{
font:14px Calibri;
border:1px solid #3EA99F;
-webkit-box-flex:1;
margin:20px;
padding:20px;
}
check the jsFiddle for more

nested float/nested row inside a column

I'm trying align two tables side by side in a floated left div. I think I've got how to horizontally align divs in general with floats but in my example below, once I create 3 columns, all floated left, I can't get the two tables in the 3rd column in the div.nestedHorizontalTables to display side by side. I tried display:inline-block but they still keep stacking vertically.
html
<div class="main-content">
<div class="column1">
<table>table1</table>
</div>
<div id="column2">
<!--I want a group of 4 vertical pie charts here-->
<div id="pie1"></div>
<div id="pie2"></div>
<div id="pie3"></div>
<div id="pie4"></div>
</div>
<div id="column3">
<div class="nestedHorizontalTables">
<table id="tab2">table2</table>
<table id="tab3">table3</table>
</div>
<table>Table4</table>
<div class="nestedHorizontalPieAndTable">
<table>table5</table>
<div id="pie6"></div>
</div>
</div>
</div>
css
#column1{
float:left;
width:40%;
}
#column2{
float:left;
width:20%;
}
#column3{
float:left;
width:40%;
}
.nestedHorizontalTables{
display:inline-block;
}
#tab2{
width:80%;
}
#tab3{
width:20%;
}
thanks
.main-content
{
margin:0;
padding:0;
float:left;
width:100%;
}
.column1 {
margin:0;
float: left;
width: 40%;
}
#column2 {
margin:0;
float: left;
width: 20%;
}
#column3 {
margin:0;
float: left;
width: 40%;
}
.nestedHorizontalTables {
display: inline-block;
}
#tab2 {
width: 80%;
}
#tab3 {
width: 20%;
}
<div class="main-content">
<div class="column1">
<table>table1</table>
</div>
<div id="column2">
<!--I want a group of 4 vertical pie charts here-->
<div id="pie1">hello</div>
<div id="pie2"></div>
<div id="pie3"></div>
<div id="pie4"></div>
</div>
<div id="column3">
<div class="nestedHorizontalTables">
<table id="tab2">table2</table>
<table id="tab3">table3</table>
</div>
<table>Table4</table>
<div class="nestedHorizontalPieAndTable">
<table>table5</table>
<div id="pie6"></div>
</div>
</div>
</div>
You may try this
If you just want the two tables inside nestedHorizontalTables to be displayed side by side, add float:left to both.
#tab2 {
width:80%;
float:left;
}
#tab3 {
width:20%;
float:left;
}
Here is a jsFiddle to help you.

Unwanted spacing with css display and table-cell

I am having difficulties in understanding the nature of table and table-cell when used in css.
Consider the following: http://jsfiddle.net/dd7h7/3/.
HTML
<div class="widget">
<div class="button">
<div class="content">
<div class="icon">A</div>
<div class="label">ABC</div>
</div>
</div>
<div class="button">
<div class="content">
<div class="icon">B</div>
<div class="label">ABCDEF</div>
</div>
</div>
<div class="button">
<div class="content">
<div class="icon">C</div>
<div class="label">ABCDEFGHI</div>
</div>
</div>
</div>
CSS
.widget {
display:block;
margin:0px;
padding:0px;
}
.button {
display:inline-block;
border:1px solid red;
margin:0px;
padding:0px;
}
.content {
display:table;
width:100%;
height:100%;
margin:0px;
padding:0px;
border-spacing:0;
border-collapse:collapse;
}
.icon {
display:table-cell;
width:15px;
height:15px;
margin:0px;
padding:0px;
vertical-align:middle;
text-align:center;
}
.label {
display:table-cell;
margin:0px;
padding:0px;
padding-left:3px;
vertical-align:middle;
}
Im trying to make a widget containing some buttons, that are positioned alongside each other. But I don't understand where the space between the red boxes comes from. How do I get rid of it?
Thanks
Inline elements (in your case the .button divs) are sensitive to white space, you can get rid of that space in a variety of ways, including:
Removing the space between the elements
Using HTML comments (<!-- -->) to occupy the gap
Floating the elements left
Example of removing the white space between elements:
<div class="widget">
<div class="button">
<div class="content">
<div class="icon">A</div>
<div class="label">ABC</div>
</div>
</div><div class="button">
<div class="content">
<div class="icon">B</div>
<div class="label">ABCDEF</div>
</div>
</div><div class="button">
<div class="content">
<div class="icon">C</div>
<div class="label">ABCDEFGHI</div>
</div>
</div>
</div>
jsFiddle example
Example of using HTML comments:
<div class="widget">
<div class="button">
<div class="content">
<div class="icon">A</div>
<div class="label">ABC</div>
</div>
</div><!--
--><div class="button">
<div class="content">
<div class="icon">B</div>
<div class="label">ABCDEF</div>
</div>
</div><!--
--><div class="button">
<div class="content">
<div class="icon">C</div>
<div class="label">ABCDEFGHI</div>
</div>
</div>
</div>
jsFiddle example
Example of using float:
.button {
display:inline-block;
border:1px solid red;
margin:0px;
padding:0px;
float:left;
}
jsFiddle example
So in short this really doesn't have to do with display:table-cell but everything to do with display:inline and inline-block.
in this fiddle i removed the space simply using
float:left;
http://jsfiddle.net/dd7h7/5/
inline-block is adding that unnecessary space.
You can do a little trick with font size:
.widget {
display:block;
margin:0px;
padding:0px;
font-size: 0;
}
.button {
display:inline-block;
border:1px solid red;
margin:0px;
padding:0px;
font-size: initial;
}
I think you should add
float:left
to
.button
so CSS should be like this
.button {
display:inline-block;
border:1px solid red;
margin:0px;
padding:0px;
float: left;
}
Hope, that will help. :)

DIV inline-block not aligning horizontally

I have five columns which I aligned using display:inline-block It works fine, but there is one problem. When I refresh the page for about 4 or 5 times while the first column is on the top the other 4 columns go to the bottom of it and when I refresh again it gets back to its original place. I couldn't figure out what is causing this and the content inside the columns are coming from database. can someone give me hint?
CSS
.col1
{
display:inline-block;
vertical-align:top;
width:225px;
}
.col2
{
display:inline-block;
vertical-align:top;
width:225px;
}
.col3
{
display:inline-block;
vertical-align:top;
width:225px;
}
.col4
{
display:inline-block;
vertical-align:top;
width:225px;
}
.col5
{
display:inline-block;
vertical-align:top;
width:225px;
}
.col_content_wrap
{
background-color:#fff;
border:1px solid #ddd;
border-radius:5px 5px 5px 5px;
box-shadow:4px 4px 1px #eee;
margin-bottom:10px;
}
.imgwrap
{
height:169px;
position:relative;
width:223px;
}
.price_wrap
{
border-top:1px solid silver;
height:50px;
}
.price
{
float:right;
margin:10px;
}
HTML
<div clas="col1">
<div class="col_content_wrap>
<div class="imgwrap">image here
<div class="price_wrap"><div class="price">
</div>
</div>
</div>
</div>
<div clas="col2">
<div class="col_content_wrap>
<div class="imgwrap">image here
<div class="price_wrap"><div class="price">
</div>
</div>
</div>
</div>
<div clas="col3">
<div class="col_content_wrap>
<div class="imgwrap">image here
<div class="price_wrap"><div class="price">
</div>
</div>
</div>
</div>
<div clas="col4">
<div class="col_content_wrap>
<div class="imgwrap">image here
<div class="price_wrap"><div class="price">
</div>
</div>
</div>
</div>
<div clas="col5">
<div class="col_content_wrap>
<div class="imgwrap">image here
<div class="price_wrap"><div class="price">
</div>
</div>
</div>
</div>
You are missing an endquote for each of the <div class="col_content_wrap> elements.
Also, in each of your html blocks, you have 5 <div>'s and only 4 </div>'s