why aren't these divs displayed side-by-side? - html

I've created the following UI components which serve as a legend:
http://codepen.io/ac123/pen/peKgjP
<div id="MapKeys">
<div id="RegionalSupply">
<div class="header">Regional supply</div>
<div class="circle"></div>
<div class="spacer"></div>
<div class="detail">Circles sized by the amount of change from the previous period</div>
</div>
<div id="CorridorNetFlowDirection">
<div class="header">Corridor net flow direction</div>
<div class="dottedLine1">
<div class="part1"></div>
<div class="part2"></div>
<div class="part3"></div>
</div>
<div class="spacer"></div>
<div class="detail">Lines sized by the amount of change in net flow from the previous period</div>
<div class="separator"></div>
<div class="dottedLine2">
<div class="part1"></div>
<div class="part2"></div>
<div class="part3"></div>
</div>
<div class="spacer"></div>
<div class="detail">Change in flow direction</div>
</div>
</div>
</div>
#MapKeys
{
text-align:left;
height:200px;
width:260px;
display:inline-block;
vertical-align:top;
.header{
font-size:16px;
padding-bottom:6px;
}
#RegionalSupply{
border:solid lightgrey 1px;
padding:10px;
display:inline-block;
& > .circle {
vertical-align:top;
width: 14px;
height: 14px;
background: lightgrey;
position:relative;
top:2px;
display:inline-block;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
}
& > .spacer {
width:5px;
display:inline-block;
}
& > .detail{
width:175px;
font-size:12px;
display:inline-block;
}
}
#CorridorNetFlowDirection{
border:solid lightgrey 1px;
padding:10px;
vertical-align:top;
display:inline-block;
& > .dottedLine1
{
font-size: 0px;
position:relative;
top:4px;
height:10px;
display:inline-block;
vertical-align:top;
& > .part1{
width: 14px;
background: lightgrey;
display:inline-block;
height:10px;
}
& > .part2{
width: 3px;
background: none;
display:inline-block;
height:10px;
}
& > .part3{
width: 14px;
background: lightgrey;
display:inline-block;
height:10px;
}
}
& > .separator
{
height:1px;
}
& > .dottedLine2
{
font-size: 0px;
position:relative;
/*top:4px;*/
display:inline-block;
& > .part1{
width: 14px;
background: #077CAB;
display: inline-block;
height:10px;
}
& > .part2{
width: 3px;
background: none;
display: inline-block;
height:10px;
}
& > .part3{
width: 14px;
background: #077CAB;
display: inline-block;
height:10px;
}
}
& > .spacer {
width:5px;
display:inline-block;
}
& > .detail{
width:150px;
font-size:12px;
display:inline-block;
}
}
}
I was expecting these divs to display side-by-side b/c the parent divs and child divs are all defined with display:inline-block. How could I update my code to make these UI components display with the same with and height similar to this?:
https://www.dropbox.com/s/dhhkcx4dvczyjgx/updated-map-key.png?dl=0

They child divs of MapKeys are display in inline-block..It is just that width you set on MapKeys (width:260px;)that is causing the second child element to break to another line
To illustrate adjust the width of MapKeys to 2600px codepen here

because the parent element has the same width as child items.
#MapKeys
{
text-align:left;
height:600px; /*Increase it so that div can be side by side.*/
width:260px;
}

Related

Grid Box Shift between divs

I am trying to make a mini grid post layout using css. But i have a problem with divs. I have try it in this demo page. And I do not get the shape I want. I want to make it like the screenshot
I try it like this CSS codes:
.div {
position:relative;
float:left;
width:100%;
border-radius:5px;
-webkit-border-radius:5px;
-moz-border-radius:5px;
background-color:#1d1f20;
}
.div:nth-child(1){
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(2){
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(3){
width:400px;
padding-top:400px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(4){
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(5){
width:365px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(6){
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
HTML
<div class="container">
<div class="div"></div>
<div class="div"></div>
<div class="div"></div>
<div class="div"></div>
<div class="div"></div>
<div class="div"></div>
</div>
How can i get the screenshot within css ? Anyone can help me here ?
You can use a lot of solutions:
Solution one:
Use the new column-count. DEMO.
Check the browser compatibility.
Solution two:
Use display:inline-block;. DEMO.
Check the browser compatibility.
Solution three:
Using flexbox. DEMO.
Check the browser compatibility.
Solution four:
Use JQuery, I suggest you the Masonry plugin (usually used for galleries) . DEMO.
I am not sure if this is what you are looking for, i had to restructure your html to achive that here is the link:http://codepen.io/saa93/pen/ENjNgy
<style>
body,html {
padding:0px;
margin:0px;
width:100%;
height:100%;
}
.container {
position:relative;
width:100%;
max-width:1010px;
min-height:400px;
margin:0px auto;
}
.div {
position:relative;
float:left;
width:100%;
border-radius:5px;
-webkit-border-radius:5px;
-moz-border-radius:5px;
background-color:#1d1f20;
}
.div:nth-child(1) {
background: transparent none repeat scroll 0 0;
float: left;
width: 370px;
}
.div:nth-child(3){
width:180px;
float:left;
}
.div:nth-child(1) > .div:nth-child(1){
background-color:#1d1f20;
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(1) > .div:nth-child(2){
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(1) > .div:nth-child(3) {
margin-bottom: 5px;
margin-right: 5px;
padding-top: 185px;
width: 365px;
}
.div:nth-child(2) {
margin-bottom: 5px;
margin-right: 5px;
padding-top: 370px;
width: 400px;
}
.div:nth-child(3) > .div:nth-child(1){
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
.div:nth-child(3) {
float: left;
width: 180px;
}
.div:nth-child(3) > .div:nth-child(2){
width:180px;
padding-top:180px;
margin-right:5px;
margin-bottom:5px;
}
</style>
<div class="container">
<div class="div">
<div class="div"></div>
<div class="div"></div>
<div class="div"></div>
</div>
<div class="div"></div>
<div class="div">
<div class="div"></div>
<div class="div"></div>
</div>
</div>
I hope this helps :)

Why won't my CSS elements center?

I am trying to have my child elements be vertically centered on their parent elements. Something is wrong with my css code but I can't tell what it is:
css:
#parent_div_1, #parent_div_2, #parent_div_3{
width:90%;
height:20%;
margin-right:10px;
border:2px solid #a1a1a1;
padding-left: 5%;
padding-right: 5%;
padding-top: 5%;
padding-bottom: 5%;
background:#dddddd;
border-radius:25px;
vertical-align:middle;
margin:4px;
}
.child_div_1{
float:left;
margin-right:5px;
border-radius: 2px;
border:2px solid #a1a1a1;
background:#dddddd;
vertical-align:middle;
}
html:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<div id='parent_div_1'>
<div class ='child_div_1'>asd</div>
<div class ='child_div_1'>asd</div>
</div>
<div id='parent_div_2'>
<div class ='child_div_1'>asd</div>
<div class ='child_div_1'>asd</div>
</div>
<div id='parent_div_3'>
<div class ='child_div_1'>asd</div>
<div class ='child_div_1'>asd</div>
</div>
link to my JSFiddle: http://jsfiddle.net/wasingej/Y4FA5/
A quick solution is to set
display: table; for #parent_div_1, #parent_div_2, #parent_div_3
and
display: table-cell; for .child_div_1
Add display: inline-block to the parent div style.
#parent_div_1, #parent_div_2, #parent_div_3{
...
vertical-align:middle;
display: inline-block;
...
}
JSFiddle: http://jsfiddle.net/9Y7Cm/5/
Add Display:inline-block; to your css on #parent_div_1, #parent_div_2, #parent_div_3:
CSS
#parent_div_1, #parent_div_2, #parent_div_3{
width:90%;
height:20%;
margin-right:10px;
border:2px solid #a1a1a1;
padding-left: 5%;
padding-right: 5%;
padding-top: 5%;
padding-bottom: 5%;
background:#dddddd;
border-radius:25px;
vertical-align:middle;
margin:4px;
display:inline-block; /* ADDED CSS */
}
.child_div_1{
float:left;
margin-right:5px;
border-radius: 2px;
border:2px solid #a1a1a1;
background:#dddddd;
vertical-align:middle;
}
DEMO HERE: http://jsfiddle.net/Y4FA5/21/
<style>
body{
padding: 0;
margin: 0;
margin:0px auto;
}
#main{
position: relative;
width:500px;
height:500px;
}
#abc{
text-align:center;
background-color:#0F0;
height:250px;
display: table;
width: 100%;
}
#abc span {
vertical-align:middle;
display: table-cell;
}
</style>
<div id="main">
<div id="abc">
<span>asdfasdfafasdfasdf<br/> sdfjdsl flkjdsflk sjdflkjdsf </span>
</div>
</div>

div content table cell settings

Please find below fiddle what i tried
http://jsfiddle.net/9LdEc/
code:
html:
<div id="CorpDealerSearch">
<div class="row">
<div class="left">
Quarter To Date
</div>
<div class="left">
914
</div>
<div class="left">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAAAZCAYAAACM9limAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACoSURBVFhH7dkhDoMwFIfxJ5EcieNwG5IZJJY7IDhCBTeYm0JCgviTEJaxAUnfbL8mdVVffn0VNTMT+7KBifVdYIdCmF8YhLm5KoQhjG+KIgYxiPEVQIyvFzMGMdI4ztuOWUmJaZpBef5QllUqilZl2SmE12WnpMK8C0zTor5/qq4DYWKuz/FMkmJiIhGGVynGyecMYhCDGF8BxPh6MWMQ86cY/pXO/0or0qcGh0OW3F8AAAAASUVORK5CYII=">
</div>
<div class="left">
<span>OFF TIER2</span>
</div>
</div>
</div>
css:
#CorpDealerSearch{
display:table;
padding : 5px;
border: 2px solid gray;
border-radius:3px;
}
.row{
display:table-row;
}
.left {
display:table-cell;
display:inline-block;
padding:5px;
}
But I want the design like the screenshot below. How can I modify the fiddle to get the design like this?
I need to do changes only for the last cell.
I have updated your fiddle:
http://jsfiddle.net/9LdEc/4/
I have added some of classes to your html and used the following css:
body {
font-family: Arial;
}
#CorpDealerSearch {
display:table;
padding : 5px;
border: 2px solid gray;
border-radius:5px;
vertical-align: middle;
line-height: 25px;
}
#CorpDealerSearch a,
#CorpDealerSearch a:hover,
#CorpDealerSearch a:visited {
color: red;
font-weight: bold;
}
.row {
display:table-cell;
vertical-align: middle;
}
.left {
display:table-cell;
display:inline-block;
padding-left:5px;
padding-right: 5px;
}
.tier {
border-left: 2px dotted black;
background-color: lightgreen;
}
Is this what you wanted?

Any idea how to do this in css?

Any idea how to do this using css ?
I'm looking for a good and clear way to do this.
HTML
<div class="line"></div>
<span>OR</span>
<div class="line"></div>​
CSS
div.line
{
width:1px;
background-color:Gray;
height:40px;
margin:10px;
}
span
{
font-weight:bold;
}
Live Sample
​
HTML
<div class="orWrapper">Or</div>​
CSS
.orWrapper {
text-transform: uppercase;
}
.orWrapper:before,
.orWrapper:after {
content: "";
display: block;
height: 50px;
margin-left: 10px;
border-left: 1px solid #000000;
}
​
DEMO
The easiest way to do it is just use three divs and border property:
your html:
<div class="vertical">
</div>
<div>
OR
</div>
<div class="vertical">
</div>
your css :
.vertical{
border-left:thin solid black;
height:30px;
margin-left:10px;
}​
fiddle for testing: http://jsfiddle.net/SURzN/
working example: http://jsfiddle.net/fTGuV/
css:
.line
{
height:30px;
float:left;
margin-left:10px;
border: solid 0px #000000;
width:1px;
border-left-width: 2px;
}
html:
<div class="line">
</div>
<div style="clear:both;"></div>
<div>OR</div>
<div class="line">
</div>
<div style="clear:both;"></div>
HTML
<div class="line"><div class="txt">Or</div> <span></span></div>​
CSS
span{height:100%; display:block; margin:0 15px; border-left:1px solid black}
.line{width:30px; margin:10px; position:relative; height:200px; text-align:center}
.txt{position:absolute; top:45%; left:4px; width:20px; height:25px; background:white}
DEMO
​
Easiest thing i did :-
​<div Class="myclass"></div>
<div>OR</div>
<div Class="myclass"></div>​
CSS
​.myclass{
width:1px;
height:30px;
background-color:black;
margin-left:10px;
}
DEMO
I would keep it all in the same box...
HTML
<span class="vertical-bar">
<span>Or</span>
</span>​
CSS
.vertical-bar {
background: url(http://dl.dropbox.com/u/2179487/black_pixel.png) center top repeat-y;
float: left;
padding: 100px 0;
}
.vertical-bar span {
background-color: white;
text-transform: uppercase;
}​
Demo: http://jsfiddle.net/PjPAU/

Variable height for multiple columns of div

I want to put 3 div like columns. The one on the left and the one the right have a content and variable length. The one in the middle is a divider.
My CSS is:
html
{
background:url(../img/texture.png) 50% 0 repeat #fff;
}
body
{
font:13px/20px "Trebuchet MS", Helvetica, sans-serif;
position:relative;
min-width:960px;
}
html, body
{
height:100%;
}
.main
{
background-color:#f8f8f8;
padding:2px;
border:1.5px solid #000000;
border-radius:1em;
-webkit-border-radius:1em;
-moz-border-radius:1em;
-o-border-radius:1em;
margin:auto;
width:950px;
box-shadow:0 0 20px #585858;
word-wrap:break-word;
}
section#content
{
padding:10px 0px;
overflow:hidden;
}
section#content #text
{
margin:10px 20px 0px;
text-align:center;
}
#text #login
{
width:40%;
margin-left:5%;
margin-right:5%;
float:left;
text-align:left;
}
#text #registration
{
width:40%;
margin-left:5%;
margin-right:5%;
float:right;
text-align:left;
}
#text #divider_ver
{
float:left;
height:100%;
width:1px;
background:#000000;
}
And my JSP:
<body>
<div class="main">
<section id="content">
<div id="testo">
<div id="text">
<div id="login">
...
</div>
<div id="divider_ver"></div>
<div id="registration">
...
</div>
</div>
</div>
<div class="clear"></div>
</section>
</div>
</body>
The problem is that the divider won't show up. If I set its height like: min-height:100px; it will, but will have fixed height (100px). I want it to have the height of the taller between the other 2 div, but I can't do it.
http://jsfiddle.net/2mjet/1/
Here:
CSS changes
section#content #text
{
margin:10px 20px 0px;
text-align:center;
overflow: hidden;
}
#text #divider_ver
{
float:left;
padding-bottom: 10000px;
margin-bottom: -10000px;
width:1px;
background:#000000;
}
Simple +padding -margin with overflow:hidden container, but it's nice trick to remember.