Previous Message
Next Message

<a> inside a <p> with <a> display:block, good idea? (phylosophyc question?)

Sent by Eric A. Meyer on 22 March 2004 03:03


At 17:33 +0100 3/21/04, Paolo Candelari wrote:

>I'm not sure if this is a question concerning this list but I try.

    It's mostly on-topic, actually.

>Maybe this is a phylosophyc question, but sometime I have problem to 
>understand how much CSS can change normal visual rendering and in 
>part semantic of an element.

    That's a tough one, but I think understanding it helps people in 
practical ways.  I'll try to make it as clear as possible.
    CSS does not change the semantic meaning of an element; it can't. 
The most you can do with CSS is alter the way an element is 
displayed.  So just because I make all the 'p' elements in my HTML 
document inline, that doesn't mean they aren't paragraphs.  They are, 
and they're still block-level elements.  They're just not generating 
block-level boxes.
    A lot of people get tripped up at precisely that point.  We're 
very used to thinking that the appearance of a thing signifies the 
nature of the thing.  That correspondence can be broken.  In HTML, an 
'h1' is always a block-level element for the purposes of document 
structure.  Thus, it can only contain inline elements.  Ditto a 'p' 
element.  The 'a' element is defined to be an inline-level element. 
A 'div', which can contain darned near anything, is a flow element.
    Very similar terms are of course used by CSS.  You can make an 
element generate a block box, or an inline box.  (Or no box at all, 
if you use 'none'.)  This DOES NOT change the structural role of an 
element.  It just determine what kind of box the element will 
generate (or not).
    The practical payoff is this:  CSS doesn't allow you to change the 
defined rules of a language.  In HTML, the following isn't permitted:

    <a href="blah.html">
    <p>Oh, this is so wrong!</p>
    <p>I'm not kidding!</p>
    </a>

That's invalid markup.  It will remain invalid markup even if you 
apply the following style sheet:

    a {display: block;}
    p {display: inline;}

Why?  Because those rules just affect display.  They don't alter the 
fundamental nature of the elements any more than my changing clothes 
will reconfigure my skeleton.
    So to get back to your original question, there's nothing 
semantically different about your example no matter what styles you 
apply.  There is nothing wrong in either a practical or theoretical 
sense with making a link inside a paragraph generate a block box, 
except possibly the actual display, which might be considered ugly by 
some.  But that's a matter of taste.

-- 
Eric A. Meyer (http://www.meyerweb.com/eric/), List Chaperone
"CSS is much too interesting and elegant to be not taken seriously."
   -- Martina Kosloff (http://www.mako4css.com/)
______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message