2

I have a unordered list, with each list element containing two spans (say span A and span B). Now I need to format these so that they are placed horizontally across the screen, when span A always on top of span B.

Eg.  spanAItem1 spanAItem2 spanAItem3
     spanBItem1 spanBItem2 spanBItem3

How can I do this using some creative CSS?

3 Answers 3

5

Something like this will get you close:

ul {float: left; list-style-type:none;}
ul li {float: left; margin-right:20px;}
ul li span {display:block}

*edited to address your comment. Take it from there :)

Sign up to request clarification or add additional context in comments.

2 Comments

float:left elements without a clear:both before closing the parent element (</ul> in this case) will yield funny results so you must be careful with that.
Thats pretty close to what I need. i just need to remove the bullets themselves, and add more space between elements. How can I do that?
2

Following Triptych's response:

  • Be sure to add a <br clear="all" /> or a <div style="clear: both"></div> or anything that implements clear:both behaviour after the </ul> tag.

  • To remove the bullets, use the list-style-type property:

ul {float: left; list-style-type: none;}

  • To add more space between elements, use the margin property:

ul li {float: left; margin: 10px;}

Comments

1

To add on to @Joel Alejandro and @Tryptych, if you set a width to the ul, the lis will wrap to the next line. However, IE6 will not wrap properly, so if older browsers are a concern, adding a class of "row" to the element at the beginning of every row along with .row{clear:both} will be the best solution, as @Joel Alejandro noted.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.