Reputation: 110
so i got this list of divs 200 by 200 but they display vertically now i pretty much want my whole site to be horizontal driven like the metro ui
body {
background-color: blue;
}
div {
display: inline;
background-color:black;
width: 200px;
height: 200px;
margin: 10px;
padding: 5px;
border: solid 2px yellow;
}
if i apply display: inline, they all shrink??? why DO: uncomment display: inline; in jsfiddle css and see
whats a good way to lay everything horizontal or inline
Upvotes: 2
Views: 2127
Reputation: 2169
You can use the text-align: justify
for the div.wrapper
, and you can use the display:inline-block
for the div list. Like this:
<div class="wrapper">
<div id="search_tile" class="search_tile"></div>
<div id="timeline_tile" class="timeline_tile"> </div>
<div id="conversations_tile" class="conversations_tile"></div>
<div id="source_tile" class="source_tile"></div>
<div id="11_tile" class="demo_11_tile"></div>
<div id="14_tile" class="demo_14_tile"></div>
<div id="12_tile" class="demo_12_tile"></div>
<div id="13_tile" class="demo_13_tile"></div>
<div class="placeholder"></div>
<div class="placeholder"></div>
</div>
body{
background-color: blue;
}
.wrapper {
letter-spacing: -4px;
word-spacing: -4px;
font-size: 0;
text-align: justify;
}
.wrapper:after {
content:"";
display:inline-block;
width: 100%;
}
.wrapper div{
font-size: 16px;
letter-spacing: normal;
word-spacing: normal;
display:inline-block;
*display: inline;
zoom:1;
background-color:black;
width: 200px;
max-width: 200px;
height: 200px;
margin: 10px;
padding: 5px;
border: solid 2px yellow;
-webkit-transition: max-width 500ms ease-in-out, height 500ms ease-in-out;
-moz-transition: max-width 500ms ease-in-out, height 500ms ease-in-out;
-ms-transition: max-width 500ms ease-in-out, height 500ms ease-in-out;
-o-transition: max-width 500ms ease-in-out, height 500ms ease-in-out;
transition: max-width 500ms ease-in-out, height 500ms ease-in-out;
}
.wrapper .placeholder {
width: 200px;
height: 0;
border: none;
background:none;
}
Please view the demo. If you are interested, you can click here and here.
Upvotes: 1
Reputation: 41832
Giving white-space: nowrap
to the body tag and display: inline-block
to the div tag does the trick.
Upvotes: 3
Reputation: 24985
You can fix this a few different ways:
Change display: inline;
to display: inline-block
as shown here
Add float: left;
as shown here
Leave everything as-is and add some content to your divs as shown here
Upvotes: 0
Reputation: 6877
We’ve been using floats for layout pretty much since we left tables behind. It’s a quirky solution that can often cause troubles, but if you know what you’re doing, it works.
One interesting alternative to floats that people are turning to more and more lately is to set the display value of an element to inline-block.
div{
display: inline-block;
background-color:black;
width: 200px;
height: 200px;
margin: 10px;
padding: 5px;
border: solid 2px yellow;
}
Upvotes: 0
Reputation: 499
Depends on exactly what you want. This will make them go horizontally until the end of the width. JsFiddle
HTML:
<div id="search_tile" class="search_tile"></div>
<div id="timeline_tile" class="timeline_tile"></div>
<div id="conversations_tile" class="conversations_tile"></div>
<div id="source_tile" class="source_tile"></div>
<div id="11_tile" class="demo_11_tile"></div>
<div id="14_tile" class="demo_14_tile"></div>
<div id="12_tile" class="demo_12_tile"></div>
<div id="13_tile" class="demo_13_tile"></div>
CSS:
body
{
background-color: blue;
width:100%;
}
div{
/*display: inline;*/
display:inline-block;
background-color:black;
width: 200px;
height: 200px;
margin: 10px;
padding: 5px;
border: solid 2px yellow;
}
Upvotes: 0
Reputation: 324610
Inline elements cannot have a set width or height.
Block elements cannot be side-by-side (float
is cheating :p)
display:inline-block
is the best of both worlds ;)
Upvotes: 1