tags:

views:

178

answers:

4

This should be easy, or perhaps impossible :)

I have this kind of HTML output

<ul>
   <li>one</li>
   <li>two
      <ul>
          <li>a</li>
          <li>b</li>
      </ul>
   </li>
   <li>three</li>
</ul>

and I would like it to appear as

one two three
    a   b

how can I do this with pure CSS? I can modify the HTML to some extent if necessary (but I would rather not).

+4  A: 

You're asking about "pure" CSS. Pure CSS is to use the best semantic tag for the job, and that means that if you really have tabular data, which this looks like it might be, than you should use a table.

Joel Coehoorn
was just thinking that same thing and I was going to add it to the question. Problem is then I have to get in there and futz with the templates that produce the HTML, but yes, I guess that's why I get paid. Thanks.
Yar
+1. Tables get a bad wrap for being overused in page layouts for so many years (when there weren't good alternatives). However, there's nothing wrong with using HTML tables for tabular data. In fact it's typically the cleanest, easiest, and most cross-browser-friendly way to do it.
Steve Wortham
What if you don't have control of the HTML? Then you'd use Zac's answer below.
Yar
A: 

You can use the css tag "list-style-type:none" ie

ul li { list-style-type: none; display: inline; }

ul li ul li { list-style-type: none; display: inline; }

chotchki
That's the _first_ step, but it's incomplete because it won't line things up like he wants.
Joel Coehoorn
yeah trying to go horizontally thanks though
Yar
oops forgot you have to add a "display: inline;" as well.
chotchki
okay, that's cool, but the problem -- and it's probably not solvable in CSS -- is to get the second line as the second line and not interrupting the first.
Yar
With your current HTML, I'm pretty sure you won't be able to pull it off without using CSS2 child selectors and positioning each element.
chotchki
+1  A: 

You could accomplish this with some floats and absolute positioning

ul li { list-style-type: none; display: inline; float: left; margin: 0 4px;}
ul.first {position: absolute; top: 0; left: 0;}
ul li ul li ul{ list-style-type: none; display: inline; float: left;position: absolute; top: 30px; left: 0; margin-top: 30px;}
ul.second {position: absolute; top: 30; left: 50;}

and

<ul class="first">
   <li>one</li>
   <li>two
      <ul class="second">
          <li>a</li>
          <li>b</li>
      </ul>
   </li>
   <li>three</li>
</ul>
zac
really? I'll have to try this out immediately. If it works you'll win best answer and my undying gratitude until the project gets changed and this answer doesn't even get used :)
Yar
A: 

To take Zac's answer a little further, you can do the CSS addressing without modifying the HTML whatsoever. Then it would look like this:

<style>
ul li { list-style-type: none; display: inline; float: left; margin: 0 4px;}
ul  {position: absolute; top: 0; left: 0;}
ul li ul li ul{ list-style-type: none; display: inline; float: left;position: absolute; top: 20px; left: 0; margin-top: 30px;}
ul li ul {position: absolute; top: 20; left: 0;}
</style>

<ul>
   <li>one</li>
   <li>two
      <ul>
          <li>a</li>
          <li>b</li>
      </ul>
   </li>
   <li>three</li>
</ul>
Yar