Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline span-behaving elements

Tags:

html

css

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?

like image 278
alemjerus Avatar asked Mar 09 '10 15:03

alemjerus


People also ask

Can you have multiple spans?

The span tag is an inline element that you use to make a smaller part of content stand out with CSS or JavaScript. You shouldn't nest span unless you thoroughly know what you're doing – but you can put multiple span tags within a block-level element.

Can span have child elements?

In practice, the default display of the elements can be changed by the use of Cascading Style Sheets (CSS), although the permitted contents of each element may not be changed. For example, regardless of CSS, a span element may not contain block-level children.


2 Answers

inline-block spans should do it:

body {
  font-family: sans-serif;
}
#container span {
  display: inline-block;
  width: 5em;
  border: 1px solid black;
}
<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>
</div>
</body>

</html>
like image 57
T.J. Crowder Avatar answered Oct 06 '22 01:10

T.J. Crowder


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

span {
    display: block;
    float: left;
    height: 100px;
    width: 100px;
}
like image 33
Andy E Avatar answered Oct 05 '22 23:10

Andy E