Results 1 to 4 of 4

Thread: making link same size as controlling div

  1. #1
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Exclamation making link same size as controlling div

    Hi guys, this should be simple

    an example of what i want to do is exactly what the bbc have on their site once you go past the front page.

    http://news.bbc.co.uk/sport1/hi/football/default.stm

    The navigation on the right is where i want to focus your attention, being able to make the div that the link sits in, change to a different colour when you hover over it, but it is also the same size as the div that it sits in, not the size of the link.

    Its also like the front page of dynamic drive and the navigation on the left...surely someone can help.

    Any ideas?
    Last edited by city_coder; 06-25-2008 at 12:36 PM.
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hey city_coder...

    I haven't looked at the code of the BBC site, but what I suspect is that the links aren't in different divs. You should use an unordered list for this, like so:

    HTML Code:
    <ul>
       <li><a href="#">First link</a></li>
       <li><a href="#">Second link</a></li>
       <li><a href="#">Third link</a></li>
    </ul>
    Then, use some CSS:
    Code:
    li a {
       display:block;
       background:gray;
    }
    
    li a:hover {
       background:blue;
    }
    You might need more CSS to get the exact look you want but those are the basics.

  3. #3
    Join Date
    Feb 2008
    Location
    Coventry
    Posts
    103
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default

    ok good call, cos thats what iv got working so far, iv also figured that i have to use

    Code:
    li:hover {
       background:blue;
    }
    to get the background of the li to change

    but that doesnt mean that when i click on the li, that i can get the a href to work. i need some way of stretching it to the size of the li.

    i mean it cant be that hard, the bbc can do it, the people who built the dynamic drive front page can do it, anyone?
    The important thing is not to stop questioning. Curiosity has its own reason for existing.

  4. #4
    Join Date
    Jun 2008
    Location
    Denham Springs, LA
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    By setting the css for li a display property to block, this will cause the anchor tag to stretch to the horizontal size of its container

    Code:
    li a {
      display:block;
    }
    Block elements such as tables and divs always fill their containers horizontally when no width is specified. Anchors, imgs, and all other inline elements do not, they must be converted to block elements using the display property to emulate this behavior.

    Note also that block elements do not stretch or fill their container vertically unless told to do so.

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
  •