DIV inline-block not aligning horizontally - html

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

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>

How do I make one element in a row change width when I resize the window

I am looking at overstock.com and they have a row where the logo, the search bar, and couple of icons are all in one div. But, when you resize the window the only element that changes its width is the search bar. In my example, I try to copy it, but whenever I hit a certain window width the section that has 4 circles in it drops out of the container that holds everything. Is there a way to only make one element resize when the window resizes in css?
Edit: this is not the same as the possible duplicate of another question. The primary reason why is the fact that in my questions there are three sections in one row and I am trying to only effect the middle section to resize. The other question is asking how to fill a remaining space with only two sections. In addition to they only want the right section to take up the remaining space. That is not what I'm trying to do, I only want the middle section to resize when I resize the window
CSS
.container {
border:1px solid grey;
height:60px;
margin: 15px auto;
position:relative;
}
.container.a > div {
}
#search input {
width:auto;
border-radius:5px;
border-color:grey;
width:100%;
}
.icon {
background:crimson;
border-radius:50%;
height:60px;
width:60px;
display:inline-block;
}
#icon-set {
margin-left:15px;
}
#icon-set:after {
display:table;
content:"";
clear:both;
}
.log {
font-size:36px;
font-weight:bold;
margin-right:15px;
}
.search-bar {
max-width:700px;
width:100%;
position:relative;
max-height:35px;
align-self:center;
}
.search-bar form {
width:inherit;
padding-right:52px;
}
.inp {
width:inherit;
height:35px;
}
.but {
position:absolute;
right:0;
width:52px;
height:35px;
background:crimson;
color:white;
border-style:none;
top:0;
}
One way to do it is to treat your layout divs as table cells. apply a fixed width to your logo on the left and icons div on the right and then leave the middle div to fill the empty space.
Here's a simplified version of your code above.
.container {
display:table;
border:1px solid grey;
height:60px;
margin: 15px auto;
position:relative;
}
.log {
display:table-cell;
width:100px;
background:blue;
font-size:36px;
font-weight:bold;
margin-right:15px;
}
.search-bar {
display:table-cell;
position:relative;
max-height:35px;
align-self:center;
}
#icon-set{
display:table-cell;
width:200px;
background:red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="log">logo</div>
<div class="search-bar">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">Go!</button>
</span>
</div>
<!-- /input-group -->
</div>
<div id="icon-set"></div>
</div>
<div class="container a">
<div class="row">
<div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
<div class="log">Logo</div>
</div>
<div class="col-xs-12 col-sm-9 col-md-9 col-lg-9">
<div class="search-bar">
<form >
<input type="text" class="inp" />
<button class="but fa fa-search"></button>
</form>
</div>
<div id="icon-set" >
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
</div>
</div>
</div>
.form_section {
width:100%; height:auto; margin:0px; padding:10px; border:1px solid #ddd;
}
.log{
font-size:36px; font-weight:bold; margin-right:15px;
}
.search-bar{
float:left; width:48%; position:relative; max-height:35px; align-self:center;
}
.inp{
width:80%; height:35px; border-radius:5px 0px 0px 5px; border:1px solid #ddd; margin:0px; padding:5px 10px; float:left;
}
.but{
width:52px; height:35px; background:crimson; color:white; border-style:none; float:left;
}
.icon{
background:crimson; border-radius:50%; height:40px; width:40px; display:inline-block; margin:0px; padding:0px;
}
#icon-set{
margin-left:15px; float:right;
}
#icon-set:after {
display:table; content:""; clear:both;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container">
<div class="form_section">
<div class="row">
<div class="col-xs-12 col-sm-3 col-md-3 col-lg-3">
<div class="log">Logo</div>
</div>
<div class="col-xs-12 col-sm-9 col-md-9 col-lg-9">
<div class="search-bar">
<form >
<input type="text" class="inp" />
<button class="but fa fa-search"></button>
</form>
</div>
<div id="icon-set" >
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
</div>
</div>
</div>
</div>

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.

Placing divs side by side, but not in line

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.

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. :)