views:

220

answers:

4

I'm making a ul-based horizontal navbar, but I want to have two levels heading in each item, a bit like this:

     Nav item1            Nav item2             Nav item3
Nav item1 subtitle    Nav item2 subtitle    Nav item3 subtitle

The subtitle has to be in a different style to the main nav item. I did this first (naively?) by using a p nested inside the li, but W3C said I couldn't nest a p inside an li.

Basically, I'm trying to avoid a br, mainly because that's not proper semantics is it? Am I going about this the wrong way?

EDIT: I should have added, I want the nav item and it's subtitle in the same anchor tag, because they are one link (and I want a:hover to work). This precludes the use of multiple heading tags within the li I think.

EDIT 2: The answers were useful, thanks. An interesting thing to note - although it was said that block span == div, that's not the way the W3C validator sees it. You can always have a span nested inside an anchor, even if the span's display:block, but you can't e.g. have a display:inline h1 inside an anchor, because the validator doesn't check the CSS and HTML files together.

+4  A: 

You could use a span since that's semantically inert, then style it with display: block.

Jason DeFontes
I would personally recommend an <em>, since "semantically inert" isn't always a good thing, especially if there's actual semantical difference.
Zarel
A: 
  1. Span with display: block==div
  2. <li> <h3>title </h3> <h4>sub title </h4> </li>

(Or any of the other possible H tags.

Itay Moav
This works, although only if I don't enclose the entire contents of the li in an "a" tag, which is a bummer because I have a hover css effect on the link...
Skilldrick
Give the [a] display: block and then do it.
Itay Moav
The validator will still treat it as an inline element though.
Skilldrick
+1  A: 

My opinion is that <br /> is semantically appropriate for a line break separating a title and subtitle. You can style it differently using a <span>.

Jamie Ide
A: 

You should use a dictionary list instead of a regular unordered list. Your example should be.

<dl>
  <dt>
    Nav Item 1
  </dt>
  <dd>
    Nav Item 1 Subtitle
  </dd>
  <dt>
    Nav Item 2
  </dt>
  <dd>
    Nav Item 2 Subtitle
  </dd>
  <dt>
    Nav Item 2
  </dt>
  <dd>
    Nav Item 2 Subtitle
  </dd>
</dl>

Or in HTML5 or XHTML 2.0 You can do

<dl>
  <di>
    <dt>
      Nav Item 1
    </dt>
    <dd>
      Nav Item 1 Subtitle
    </dd>
  </di>
  <di>
    <dt>
      Nav Item 2
    </dt>
    <dd>
      Nav Item 2 Subtitle
    </dd>
  </di>
  <di>
    <dt>
      Nav Item 2
    </dt>
    <dd>
      Nav Item 2 Subtitle
    </dd>
  </di>
</dl>
Andrew Marsh