views:

70

answers:

5

Hi All,

I am creating an element on my page like so:

<a href="">
<span class="benefits">
Free entry<br />
20% off in store<br />
First to know about latest courses
</span>
</a>

The client wants the whole area clickable, and the list of benefits to display with bullet points.

As far as i am aware lists cannot be placed inside anchor tags?

I had hoped I could insert a tag before hand that I could attach the css list-style-type rules to however that didn't work. I tried then making that element a fixed width and height with a background colour, however, it didnt display properly in IE6 - which I have to support.

Any ideas?

A: 

Set display:block for the A (anchor) element. Then put the UL list inside it.

Šime Vidas
Though that will not pass validation.
Ant Ali
@Ant - XHTML may hate you for it, but it's okay in HTML5.
Spudley
@Spudley, unfortunately, the target audience that I have to code for (browsers IE6 - Latest, FF, SF, CH etc) I couldn't get away with that...
Ant Ali
I don't have IE6 here... Does my method work in IE6? If it does work, then I suggest that you switch to the HTML5 DOCTYPE and you won't have validation errors. IE6 and IE7 will be dead in less than a year anyway.
Šime Vidas
I dont know if IE6 works but if you are worried about validation then you could use this method (display: block, if it is valid) with a list created using •, as suggested in another post.
ClarkeyBoy
@Ant - HTML5 is backward-compatible with all existing browsers. You don't have to use any of the new features; just use the correct doctype, and some improvements you can use instantly, such as `<a>` tags being allowed to wrap block elements. The only browser that you *might* have trouble with is IE, and even then there are very easy hacks to deal with it (html5shiv, modernizr, etc).
Spudley
In the end I achieved it using a span with a class called bullet that I could wrap around the element that required the bullet and in the 'display' css property i set it to 'list-item'
Ant Ali
A: 

Why not just make an unordered list with the same anchor inside each list item? You can then easily add custom bullets inside each anchor tag so that the bullets are clickable, and you can using padding instead of margins to space the anchors so that they are all touching.

Mathletics
The problem with that is that the block will have a coloured background that upon hover will change. If I followed this method then I wouldnt be able to change the background of the whole element.
Ant Ali
+3  A: 
RBW_IN
I think this is probably the way I have to do it... Thanks
Ant Ali
A: 

As far as i am aware lists cannot be placed inside anchor tags?

You're right about that, and even though browsers may not care, it's not valid HTML.

My suggestion would be to use a DIV and make it clickable via JavaScript. You may still want to add a normal link inside the DIV for accessibility purposes. This way, you retain all the semantics of the markup (there's an <a> link and a <ul> list) and yet get the end result you wanted.

HTML:

<div id="box1" class="box">
  <a href="link"> ... </a>
  <ul> ... </ul>
</div>

CSS:

.box {
  width: /* something */;
  height: /* something */;
  cursor: pointer;
}

JavaScript:

document.getElementById('box1').onclick = function() {
  window.location = 'link';
}
casablanca
I really did't want to have to use javascript for something so simple.
Ant Ali
Unfortunately there isn't a simpler "valid" way to make a block clickable.
casablanca
Thanks for the suggestion anyway.
Ant Ali
A: 

You can wrap the various lines in spans w/ a class, and then use CSS to add the decorations by

  1. Adding in some left padding and attaching a background image.

  2. Try using the :before pseudo class and using CSS content to add in the bullet.

  3. I can't remember if this works, but you can also try setting the span display=list-item and list-style-type=disc

MPD