Results 1 to 4 of 4

Thread: XHTML (W3C) and DIV in a A

  1. #1
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question XHTML (W3C) and DIV in a A

    Here is what I try to do :
    I have a menu bar on the upper left part of a web page at http://www.ageuqtr.cjb.net/
    the (achieved yet) goal is to have the whole buttons to be clickable, and not only the text part of them.
    the (unachieved yet) goal is to keep this as it is, but to have it XHTML compliant...
    so far, here is how I do it :
    Code:
    <div id="button_one">
      <a href="link_of_this_button">
        <div id="button_one_inside" style="width:100%;height:100%">
          <img src="icon" />
          Button text
        </div>
      </a>
    </div>
    The problem is : <div> tags are not allowed inside <a> tags... in XHTML...
    is there a simple way to make a complete zone clickable without using such a pattern (div in an anchor) ?
    Last edited by adoxe; 11-23-2005 at 12:34 AM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Why won't this work:

    Code:
    <div id="button_one"><a href="link_of_this_button"><img src="icon" /> Button text </a></div>
    Both the image and the text are linked.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by adoxe
    Some of that content is unreadable when the background images aren't rendered. An explicit background colour should usually accompany such images.

    [...] XHTML compliant...
    XHTML is usually a waste of time, especially if you're always serving it as HTML. Still, your markup wouldn't be valid HTML, either.

    <div id="button_one_inside" style="width:100%;height:100%">
    Just so you're aware, this is equivalent to:

    Code:
    <div id="button_one_inside" style="width: 100%;">
    A percentage value for the height property must eventually be calculated against an explicit length. For example,

    Code:
    <div>
      <div style="height: 60%;">
        <div style="height: 110%;">
    might as well be:

    Code:
    <div>
      <div>
        <div>
    However,

    Code:
    <div style="height: 10em;">
      <div style="height: 60%;">
        <div style="height: 110%;">
    would be computed to:

    Code:
    <div style="height: 10em;">
      <div style="height: 6em;">
        <div style="height: 6.6em;">
    On a similar line, the width property declaration is unnecessary. Block-level elements automatically take up as much horizontal space as they can within their containing blocks. Trying to force 100% width will only cause problems if you add padding, borders, or margins, as these areas will cause the element to overflow.

    is there a simple way to make a complete zone clickable without using such a pattern (div in an anchor) ?
    Yes. Style the link (a) into a block-level element. It will then take all horizontal space, and expand vertically to contain its contents. This should also mean you can remove the outer div element, too.

    Code:
    .button {
      display: block;
    }
    
    
    <a class="button" href="..."><img alt="..." src="..."> Button text</a>
    Mike

  4. #4
    Join Date
    Nov 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Mike !
    you're my man !!!
    You gave me so much so concisely, I feel like a newbie now though, please keep yourself from making me feel this way... hehe

    I knew about the images thing but if you only could know why this was that way (not my choice, indeed...).

    So thanks again, it's awesome !

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •