views:

3119

answers:

5

Hi folks, does anyone have a suggestion for creating paragraph-type line spaces within a <li> tag that includes a hovered pop-up pseudo-class?

I have a <span> that pops up on a:hover and I want the text that pops up to be broken into 2 paragraphs. It works with <br> in FF but I want to do the right thing (now that I've discovered it's wrong!)...

Thanks,
Patrick.

html:

<div id="rightlist">
  <ul>
      <li><a href="">List item
          <span>
             words words words that are "paragraph" 1 of List item
             <br><br>
             different words that make up "paragraph" 2 of List item
          </span></a></li>

css:

#rightlist {
margin-top: 10px; margin-right: 5px; width: 387px ; height: 239px ;
background-color: #7EBB11 ;
display: table-cell; 
z-index: 100 ;
    float: right ;
}

#rightlist ul {
  text-align: left;
margin: 0;
   margin-top: 6px;
font-family: sans-serif;
font-size: 20px ;
color: black ;
}

#rightlist a 
{
    display: table-cell;
text-decoration: none; color: black; 
background: #7EBB11 ; 
}

/*appearance of the <a> item (but before the <span> tag) on hover*/
#rightlist a:hover {
color: white;
}

/*appearance of the spanned content within <a></a> tags when not hovered */
/* %%%%% important - keep position:absolute in this div %%%%% */
#rightlist a span {
display: none;
position: absolute ;
margin-left: -412px;
top: -10px; left: 10px; padding: 10px ;
z-index: 100;
width: 380px; height: 222px; 
color: white;  background-color: #7EBB11;
font: 0.75em Verdana, sans-serif; font-size: 13px ; color: black;
text-align: left;
}



/*appearance of spanned content within <a> tags when hovered*/
#rightlist a:hover span {
display: table-cell ;
}
A: 

You could stick another span in there as a "fake" p tag:

  <li><a href="">List item
      <span>
         <span>words words words that are "paragraph" 1 of List item</span>
         <span>different words that make up "paragraph" 2 of List item</span>
      </span></a></li>

And in your css:

#rightlist span span {display:block;margin:...}

Note anything you declare for #rightlist span will apply to #rightlist span span, so you might need to override some of the rules in #rightlist span span.

Oli
Tx Oli but this put the two blocks on top of each other as separate but simultaneous instances the hover. Would be ok if each text paragraph was of known size (I could specify size and position of #2 so it is below #1 etc) but unfortunately it ain't the case. Still scratching my head over this..
+2  A: 

Err there's nothing wrong with having <br> inside <a> or <span>. It's perfectly valid according to the HTML 4.01 spec.

Edit: <li> can contain <p>, <br>, and pretty much anything else.

The spec is a bit hard to read but basically says:

  • LI can contain block or inline
  • block is made of P + some other things
  • inline is made of special + some other things
  • special is made of A + BR + some other things

Regarding <a> it says:

  • A can contain inline except A
  • inline... see above
Greg
sure - but I have it inside <li> , I think that's the "legal" issue!
It's not a legal issue. LI can contain whatever you want.
Rob Kennedy
A: 

Why is your current way wrong ?

You can try this

<span>
  <p>words words words that are "paragraph" 1 of List item</p>
  <p>different words that make up "paragraph" 2 of List item</p>
</span>
Kim
<p> isn't allowed inside <span>
Greg
That's completely the point of this post, Kim. You're not allowed to put block-level elements (div, p, ul, ol, etc) inside elements like a, span, etc. It's against the specs.
Oli
A: 

Your problem may arise from the fact that you're using a <span> tag incorrectly.

Spans are supposed to be inline elements and you're styling it as though it were a block element. Admittedly you can force a span to behave as a block element by adding the right style, but this may not always be honoured by the various browsers out there.

Ideally you should be using a div instead. You can then use either p tags or further div tags to indicate the paragraphs (ideally p, since semantically they actually are paragraphs rather than unrelated blocks of text).

inferis
but can I put a <div> within a <li>? I thought that was against the specs?
There's nothing I know of in either the HTML or XHTML specs that forbids them. There's a list of prohibitions in the XHTML spec [http://www.w3.org/TR/xhtml1/#prohibitions], but divs within list items aren't mentioned.
inferis
In fact, if you look at the DTD (<!ELEMENT LI - O (%flow;)* -- list item -->) you'll notice there aren't any prohibitions whatsoever, these would, I think, be indicated by, e.g. -(DIV).
inferis
A: 

Why is it 'Wrong'?

your br tag should perhaps be coded as:

 <br />
Adrian
sorry, terrible typing: W3C strongly suggests avoiding that in a 4.01 document....
Where ? - I'm all from learning!(Also your question did not state HTML 4.01)
Adrian
It was in the validation report I got for the page that had the html code in it. You're right, should have spec'd 4.01, sorry!