Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-10-2012, 03:12 PM   PM User | #1
gribbs100
Regular Coder

 
Join Date: Feb 2006
Posts: 168
Thanks: 32
Thanked 1 Time in 1 Post
gribbs100 is an unknown quantity at this point
Making all of this div content a hyperlink. What is the correct approach?

Hello Guys,
Below is a rough example of what I am trying to accomplish. When you hover over the div, the background color changes. I also want to make the entire row a hyperlink. Now we all know that a div is a block element and cannot be inside of a href=... so I have to come up with another way to make the whole thing a link. The only solution that I came up with (not applied in the code below) is to have a transparent png image positioned absolute z-index:999 inside + over each entire container and make that a link. Is there a better way though? I really wanted to do this with a html + css approach. I didn't want to have to go a javascript route.Thanks in advance for any suggestions.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>-</title>
<style type="text/css">
body {
	background-color: #131313;
	margin: 0px;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #FFF;
}
#gallery-box {
	width: 630px;
	margin: 0px;
	float: left;
	line-height: 30px;
	overflow: auto;
}
.directory1 {
	background-color: #1c1d1e;
	float: left;
	width: 610px;
}
.directory2 {
	background-color: #121315;
	float: left;
	width: 610px;
}
.event-title {
	width: 195px;
	margin-right: 5px;
	float: left;
	padding-left: 5px;
}
.city {
	float: left;
	height: 30px;
	width: 200px;
	margin-right: 5px;
}
.date {
	float: left;
	height: 30px;
	width: 200px;
}
.directory1:hover {
	background:#fff;
	color:#000;
}
.directory2:hover {
	background:#fff;
	color:#000;
}
</style>
</head>
<body>
<div id="gallery-box">

  <div class="directory1">
    <div class="event-title">Venue 1</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
  <div class="directory2">
   <div class="event-title">Venue 2</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
  <div class="directory1">
    <div class="event-title">Venue 3</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
  <div class="directory2">
   <div class="event-title">Venue 4</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
  <div class="directory1">
    <div class="event-title">Venue 5</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
  <div class="directory2">
   <div class="event-title">Venue 6</div>
    <div class="city"><a href="wrgtre">Cit</a>y</div>
    <div class="date">Date</div>
  </div>
  
    <div class="directory1">
    <div class="event-title">Venue 7</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
  <div class="directory2">
   <div class="event-title">Venue 8</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
  <div class="directory1">
    <div class="event-title">Venue 9</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
   <div class="directory2">
    <div class="event-title">Venue 10</div>
    <div class="city">City</div>
    <div class="date">Date</div>
  </div>
  
</div>
</body>
</html>
gribbs100 is offline   Reply With Quote
Old 02-10-2012, 03:27 PM   PM User | #2
visioncom
New Coder

 
Join Date: Mar 2010
Posts: 11
Thanks: 1
Thanked 0 Times in 0 Posts
visioncom is an unknown quantity at this point
You could always use an image map. Just make the size of your map the size of your div with the appropriate coordinates. I dont forsee any reason for that not to work.
visioncom is offline   Reply With Quote
Old 02-10-2012, 04:56 PM   PM User | #3
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Good morning gribbs100,
An anchor is the easiest way to make that row a link, use spans to form the different classes inside each .directoryX since.

Something like this -
Code:
  <a href="#" class="directory1">
    <span class="event-title">Venue 1</span>
    <span class="city">City</span>
    <span class="date">Date</span>
  </a>
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
Users who have thanked Excavator for this post:
gribbs100 (02-10-2012)
Old 02-10-2012, 09:45 PM   PM User | #4
gribbs100
Regular Coder

 
Join Date: Feb 2006
Posts: 168
Thanks: 32
Thanked 1 Time in 1 Post
gribbs100 is an unknown quantity at this point
Excellent! I appreciate the help. That is perfect!
gribbs100 is offline   Reply With Quote
Reply

Bookmarks

Tags
block, div, hover, hyperlink

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:43 AM.


Advertisement
Log in to turn off these ads.