views:

426

answers:

7

How can I make the anchor tag expand to the bottom of the list item? I know I could put the anchor round the list item tag, but that breaks XHTML 1.0 Strict compliance, so I cannot do it.

<html>
  <head>
    <style>
      #listWrapper { text-align:center;}
      #list { margin-left: 0px auto; margin-right: 0px auto; width: 100%; min-height: 100%; height:100%; margin-bottom: 10px; margin-top: 0px;}
      #list ul { padding: 5px 10px 10px 10px; margin: 0; min-height: 100%;}
      #list li { clear:both; font-weight:bolder; height:auto; border-bottom: 1px solid Silver; border-left: 1px solid Silver; font-size:x-small; border-right: 1px solid Silver; list-style-type: none;}
      #list a:hover { background-color: red;}
      #list a { display:block; cursor:pointer; text-decoration: none; text-align:left; vertical-align:top; }
      #list h3 { background-color:Silver; vertical-align:top; font-size:larger; }
      #list img { height:auto; margin: 8px; float:left; vertical-align:top; border:solid 1px Silver;}   
    </style>
  </head>
  <body>
    <div id="listWrapper">
      <div id="list">
        <ul>
          <li>
            <h3>title</h3>
            <a href="#">
              <img src="/images/x.jpg" alt="" />
              Lorem ipsun........
            </a>
            <div style="clear:both;" />
          </li>
          <li>
            <h3>title</h3>
            <a href="#">
              <img src="/images/x.jpg" alt="" />
              Lorem ipsun........
            </a>
            <div style="clear:both;" />
          </li>
        </ul>
      </div>
    </div>
  </body>
</html>
A: 

use this css:

.list ul li a { display: block }
soniiic
That css is already in place, under the `#list a` selector.
Tomas Lycken
This doesn't seem to work
simon831
+1  A: 

To fill the bottom, you need to fix the image margins - right now the image is taking up too much space with it's 8px margin. To fill the top, you need to remove the bottom margin of h3.

#list h3 { margin-bottom: 0; }
#list img { margin: 5px 8px; }
Tomas Lycken
Note that I tested this on my local laptop, with no access to the file `images/x.jpg`, so the margins I suggested are for an image of `1x1 px`. If your image is of a different size, you might need to adjust the margins differently.
Tomas Lycken
A: 

I only wish there was a way to do vertical space expansion. It would make the multi-column thing much easier.

You can fudge it with JavaScript (using jQuery):

$('#list li').each(function(){
    $(this).find('a').css('min-height', $(this).height());
});

You'll have to do some tweaking to factor out padding and such, but it's solid in theory.

cpharmston
wow. but not really the kind of solution I need.
simon831
The type of solution you need does not exist, unfortunately. If it did, then you wouldn't need the faux columns technique, for example. display:table will eventually make this sort of thing possible, but I assume that you need it to work in IE. http://www.alistapart.com/articles/fauxcolumns
cpharmston
A: 

Try set height on the #list to a fixed size, and height on #list ato 100%.

Differences to your existing code:

    #list
    {
        min-height: 100px;
        height: 100px;
    }

    #list a
    {
         height:100%;
    }
awe
... but #list is not a fixed size - it varies.
simon831
The reason for this is that sometimes the browser does not understand what is the relative size if not at least one of the parents has fixed size. I think this is most an issue in Internet Explorer. But I'm glad you found the solution for your issue.
awe
+1  A: 

Put the

<br style="clear: both;"/>

inside the Anchor tag.

EDIT: changed div to br

ZippyV
that breaks XHTML 1.0 Strict compliance
simon831
Fixed, this code passed the W3 validation.
ZippyV
+4  A: 

A combination of your answers fixed it. Many thank....

#list ul { display: block; }
#list li { display: block;}
#list a { display:block; height:100%; }
simon831
A: 

Here's what I did:

<!-- teh codes -->
<style type="text/css">
  .nav-cell
  {
    height: 35px;
    padding: 0px; /* just to make sure the link will fill the entire cell */
    text-align: center;
    width: 92px;
  }
  .nav-cell-link
  {
    display: block;
    width: 100%;
    height: 100%;
  }
  .nav-cell-link-text
  {
    display: block;
    padding-top: 11px;
  }
</style>
<!-- teh codes -->
<table cellpadding="0" cellspacing="0" style="height: 35px;">
  <tr>
    <td class="nav-cell">
      <a href="#" class="nav-cell-link">
        <span class="nav-cell-link-text">Link Text</span>
      </a>
    </td>
  </tr>
</table>
<!-- teh codes -->
Brandon Montgomery