CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignCSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 2nd, 2012, 12:59 PM
emilnygaardfris emilnygaardfris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 emilnygaardfris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 34 sec
Reputation Power: 0
How to make a whole div a link?

I have a div which is styled in css to be a box, how do i make this box a link? I have tried to look it up on google, but couldn't find anything useful, so i hope that you can help me

Thank you!

Emil

Reply With Quote
  #2  
Old December 2nd, 2012, 01:11 PM
simplypixie simplypixie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 104 simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 18 h 33 m 57 sec
Reputation Power: 11
Set the anchor link within the div to be 100% width and height, so something like
Code:
a.expand {
 width: 100%;
 height: 100%;
 }

Then in your HTML
Code:
<div class="name of class">
<a href="link"  class="expand">Link text or leave blank</a>
</div>

Reply With Quote
  #3  
Old December 2nd, 2012, 03:45 PM
emilnygaardfris emilnygaardfris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 emilnygaardfris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 34 sec
Reputation Power: 0
Thanks for the advise, but sadly i can not get it to work out for me.

This is what my code looks like:

HTML
Code:
<div class="p1">
<a href="www.google.dk" class="expand">blabla</a>
</div>


CSS
Code:
a.expand {
	width: 100%;
	height: 100%;
}


It seems that the div is not able to expand.

Reply With Quote
  #4  
Old December 2nd, 2012, 04:31 PM
Nanomech's Avatar
Nanomech Nanomech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: The Pleiades
Posts: 192 Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 23 h 7 m 18 sec
Reputation Power: 7
Send a message via Skype to Nanomech
I had a go at it earlier but couldn't get the anchor to expand just the container.

I tried this:

Code:
<style type="text/css">
a
{
   width: 30%;
}
#content 
{
   width: 30%;
   border: 1px solid black;
   height: 500px;
}



</style>
</head>

<body>

<a href="somepage.php" />
    <div id="content" href="somepage.php"></div>
</a>


But as you can see, the anchor tag doesn't 'wrap' round the div like it would an image.

If you contrast that with this:

Code:
<style type="text/css">

img 
{
   width: 30%;
   height: 500px;
}



</style>
</head>

<body>

<a href="somepage.php" />
    <img src="phpwp.jpg" />
</a>


you will see why I tried the approach of putting the anchor outside the div, but it seems to span the whole page even with a width declared. Hover your mouse over the right hand side of the div with the first example and you will see it spans the whole page.

Not really sure how to fix this. Could be very simple but I can't seem to figure it out.....good question! I will like to see the answer to this!

Regards,

NM.

Reply With Quote
  #5  
Old December 2nd, 2012, 05:29 PM
Catacaustic's Avatar
Catacaustic Catacaustic is offline
Code Monkey V. 0.9
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2005
Location: A Land Down Under
Posts: 1,884 Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level)Catacaustic User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 14 h 1 m 42 sec
Reputation Power: 1798
Why not just do it the easy way:

Code:
<a href="http://example.com"><div class="class_name">Content in here<div></a>


No mucking around with more CSS, no worries with trying to fill an area, and fully valid HTML code.

Reply With Quote
  #6  
Old December 2nd, 2012, 05:58 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,830 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 16 h 41 m 29 sec
Reputation Power: 4192
The width and height properties don't apply to (non-replaced) inline elements, like <a>. You can give such elements "display:block" to make said properties work.

Setting a percentage height doesn't work as one might expect it to. I recommend you read Height and Min-Height

Quote:
But as you can see, the anchor tag doesn't 'wrap' round the div like it would an image.

That's because an <img> is a "replaced inline element", where as a <div> is a "block element".

Quote:
No mucking around with more CSS, no worries with trying to fill an area, and fully valid HTML code.

If you changed the second <div> start tag to an end tag, it would be valid HTML5, but it's certainly not valid HTML4. And if you'd like to strengthen your CSS skills, ask me more questions.

*** Thread moved to CSS forum ***
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Last edited by Kravvitz : December 2nd, 2012 at 06:01 PM.

Reply With Quote
  #7  
Old December 2nd, 2012, 07:19 PM
Nanomech's Avatar
Nanomech Nanomech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: The Pleiades
Posts: 192 Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 23 h 7 m 18 sec
Reputation Power: 7
Send a message via Skype to Nanomech
Ah I need to study more about which elements are inline and which are block. I have a vague idea of the more common elements but don't know much about why you can do certain things with 1 type and not another etc.

Thanks for answering I had a feeling it would be you lol

Regards,

NM.

Reply With Quote
  #8  
Old December 3rd, 2012, 01:49 AM
simplypixie simplypixie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 104 simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level)simplypixie User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 18 h 33 m 57 sec
Reputation Power: 11
Sorry, in my original post I was meant to change the height to a set amount, not leave at 100% (that should have just been for the width).

So if the containing div has a height of 20px, then set your class for the anchor tag to have the same height so it fills the containing div.

Reply With Quote
  #9  
Old December 5th, 2012, 02:31 PM
emilnygaardfris emilnygaardfris is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 4 emilnygaardfris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 57 m 34 sec
Reputation Power: 0
Thanks very much for all the suggestions!

@Kravvitz

That really helped me out :-)

Reply With Quote
  #10  
Old December 5th, 2012, 03:36 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,830 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 16 h 41 m 29 sec
Reputation Power: 4192
You're welcome.

Quote:
Originally Posted by Nanomech
Ah I need to study more about which elements are inline and which are block. I have a vague idea of the more common elements but don't know much about why you can do certain things with 1 type and not another etc.

It tends to come down to the purpose of the element. Some elements are used to mark up a few words or sentences (e.g. <em>, <acronym>) and they are inline elements, where as others are used to mark up blocks of content (e.g. <p>, <ul>) and those are blocks.

Does that make it any clearer to you?

Last edited by Kravvitz : December 5th, 2012 at 04:19 PM. Reason: typo correction

Reply With Quote
  #11  
Old December 5th, 2012, 04:08 PM
Nanomech's Avatar
Nanomech Nanomech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: The Pleiades
Posts: 192 Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 23 h 7 m 18 sec
Reputation Power: 7
Send a message via Skype to Nanomech
It does actually yea.

So for example, <span> is inline and let's say an <a>nchor is an inline because it's only defining a small part of your page.

Block can be <div>, <img>, <p>, <h1-6>, <table> as they define (possible) large areas of content for the site?

Kind regards,

NM.

Reply With Quote
  #12  
Old December 5th, 2012, 04:22 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,830 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 16 h 41 m 29 sec
Reputation Power: 4192
Quote:
Originally Posted by Nanomech
So for example, <span> is inline and let's say an <a>nchor is an inline because it's only defining a small part of your page.

Block can be <div>, <img>, <p>, <h1-6>, <table> as they define (possible) large areas of content for the site?

Close. An <img> is an inline element, but it's a replaced inline element, so it has some characteristics of both inline and block elements. And note that while a <table> is a block, it has "display:table" instead of "display:block" by default (except in IE7 and older).

Reply With Quote
  #13  
Old December 5th, 2012, 04:43 PM
Nanomech's Avatar
Nanomech Nanomech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: The Pleiades
Posts: 192 Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 23 h 7 m 18 sec
Reputation Power: 7
Send a message via Skype to Nanomech
Ah thanks for the info. I think I'm going to google it and look up in detail about each type of elements.

Do you know of any good, reliable sources from which to learn from?

Kind regards,

NM.

Reply With Quote
  #14  
Old December 5th, 2012, 04:59 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,830 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 16 h 41 m 29 sec
Reputation Power: 4192
Quote:
Originally Posted by Nanomech
Ah thanks for the info. I think I'm going to google it and look up in detail about each type of elements.

Do you know of any good, reliable sources from which to learn from?

Stay away from w3schools.com (which has nothing to do with w3.org).

I recommend that you read these:
Block vs. Inline, Part 1
Block vs. Inline, Part 2
Block vs. Inline, Part 3

Reply With Quote
  #15  
Old December 5th, 2012, 06:52 PM
Nanomech's Avatar
Nanomech Nanomech is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Location: The Pleiades
Posts: 192 Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level)Nanomech User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 23 h 7 m 18 sec
Reputation Power: 7
Send a message via Skype to Nanomech
I only really visit w3schools to reference HTML tags to check their possible attributes etc.

I'll give those a read now.

Kind regards,

NM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignCSS Help > How to make a whole div a link?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap