开发者

Elements to 'look like' a bullet point list inside an anchor link

I am creating an element on my page like so:

<a href="">
<span class="benefits">
Free entry<br />
20% o开发者_StackOverflow社区ff 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?


Try using the HTML character entity &bull; which looks like this: •

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

more character entities here: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references


Maybe something like this could help:

a.error::before{    
    background-color: #be1c1c;
    border-radius: 1em;
    content: " ";
    display: inline-block;
    height: 0.35em;
    margin-right: 6px;
    width: 0.35em;
}
a.error{
    color:#be1c1c;
    text-decoration:none;
    display:block;
}
ul {
    padding:1em;
    display: block;
    list-style-type: disc;
}
ul li{
    color:#be1c1c;
}
My links:
<a class="error" href="#"> item 1</a>
<a class="error" href="#"> item 2</a>
<a class="error" href="#"> item 3</a>
<br>
My list:
<ul>
  <li> item 1</li>
  <li> item 2</li>
  <li> item 3</li>
</ul>

Hope it help!


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


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.


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';
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜