views:

208

answers:

2

I want to display a list of complex, but fixed-size multiline elements, assuming that they will wrap the page line when line end is reached, making them appear by n in each row, when n depends on page width. Something like:

Mary had    Mary had    Mary had
a little    a little    a little
LAMB        LAMP        WHISKEY


Mary had
a little
TOO MUCH

How should I do that?

+4  A: 

Use a combination of display: block; float:left; and your desired width and height.

span {
    display: block;
    float: left;
    height: 100px;
    width: 100px;
}
Andy E
Floats just do too many weird things for me. :-)
T.J. Crowder
@T.J. yeah I can relate to that, I wasn't aware inline-block worked on IE6, though ;-)
Andy E
@Andy: Just *barely* ;-)
T.J. Crowder
+3  A: 

inline-block spans should do it:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Inline Block Demo Page</title>
<style type='text/css'>
body {
    font-family: sans-serif;
}
#container span {
    display: inline-block;
    width:  5em;
    border: 1px solid black;
}
</style>
</head>
<body>
<div id='container'>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
</div>
</body>
</html>
T.J. Crowder
it should be noted that `inline-block` doesn't work in IE6 :-)
Andy E
@Andy E: Actually, it does -- but IE6 will only let you set `inline-block` on elements that normally default to `inline`, not on elements that normally default to `block`. I'd remembered that backward for the example, so I've fixed that now. :-)
T.J. Crowder
@T.J. Good one! :-)
Andy E
@Andy: Thanks -- and thanks for reminding me about the IE6 weirdness!
T.J. Crowder