[SOLVED] How to make a div a link

This is a discussion on "[SOLVED] How to make a div a link" within the Web Page Design section. This forum, and the thread "[SOLVED] How to make a div a link are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 30th, 2007, 07:54
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] How to make a div a link

Hi all,
I have a div with a background image, and am trying to make the div a link. A class sould be easier as then I could apply it to rest of the buttons.

Any help will be greatly appreciated

Dan

Code: Select all
#CMS{
 background-image: url(assets/buttons/right/blue_CMSbutton.gif);
 background-repeat: no-repeat;
 background-position: center center;
 height: 40px;
 width: 150px;
 margin-left: 15px;
}
HTML: Select all
<div id="CMS"></div>
Reply With Quote

  #2 (permalink)  
Old Nov 30th, 2007, 07:57
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,661
Thanks: 0
Thanked 9 Times in 9 Posts
Re: How to make a div a link

You would have to do something like:
HTML: Select all
<a href=""><div id="CMS"></div></a>
although i would opt for a <span> rather than a <div>.
Reply With Quote
  #3 (permalink)  
Old Nov 30th, 2007, 08:09
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to make a div a link

Nice and simple

Cheers

Marc
Reply With Quote
  #4 (permalink)  
Old Nov 30th, 2007, 08:11
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,661
Thanks: 0
Thanked 9 Times in 9 Posts
Re: [SOLVED] How to make a div a link

Your welcome - that's what I'm here for!
Reply With Quote
  #5 (permalink)  
Old Nov 30th, 2007, 08:25
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: [SOLVED] How to make a div a link

As Marc said, you should use a <span>, not a <div>. If you use a <div>, you will likely make invalid code.

As a general rule, don't put block-level elements (such as <div>) inside inline elements (such as <a>). See this W3C explanation:

Quote:
Content model

Generally, block-level elements may contain inline elements and other block-level elements. Generally, inline elements may contain only data and other inline elements. Inherent in this structural distinction is the idea that block elements create "larger" structures than inline elements.
You can have the appearance of a <div> by using the CSS:

Code: Select all
span.block { display: block; }
This trick is commonly applied to <a> elements in navbars.

Last edited by MikeHopley; Nov 30th, 2007 at 08:43.
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make a div become visible on clicking a link? snappy Web Page Design 12 Jun 11th, 2008 19:25
[SOLVED] How to make an expand / collapse menu sing2trees JavaScript Forum 4 Apr 14th, 2008 12:16
[SOLVED] joining 2 queries together to make 1 query AdRock Databases 0 Nov 18th, 2007 21:37
[SOLVED] How do I Make Content available for download chrissmith Starting Out 4 Nov 11th, 2007 10:13
[SOLVED] How to make the PM pop up box? Monie JavaScript Forum 31 Nov 7th, 2007 08:38


All times are GMT. The time now is 04:59.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43