Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use CSS to make a span not clickable

Tags:

css

<html>     <head>     </head>     <body>         <div>             <a href="http://www.google.com">                 <span>title<br></span>                 <span>description<br></span>                 <span>some url</span>             </a>         </div>     </body> </html> 

I am pretty new to CSS, I have a simple case like the above. I would like to make the "title" and "some url" clickable but want to make description as non-clickable. Is there any way to do that by applying some CSS on the span so that whatever inside that span, it is not clickable. My constraint is that, I do not want to change the structure of the div, instead just applying css can we make a span which is inside an anchor tag, not clickable ?

like image 383
Shamik Avatar asked Jun 29 '10 19:06

Shamik


People also ask

Can we apply CSS on span?

The <span> tag is an inline container used to mark up a part of a text, or a part of a document. The <span> tag is easily styled by CSS or manipulated with JavaScript using the class or id attribute. The <span> tag is much like the <div> element, but <div> is a block-level element and <span> is an inline element.


1 Answers

Actually, you can achieve this via CSS. There's an almost unknown css rule named pointer-events. The a element will still be clickable but your description span won't.

a span.description {     pointer-events: none; } 

there are other values like: all, stroke, painted, etc.

ref: http://robertnyman.com/2010/03/22/css-pointer-events-to-allow-clicks-on-underlying-elements/

UPDATE: As of 2016, all browsers now accept it: http://caniuse.com/#search=pointer-events

like image 169
FRAGA Avatar answered Sep 22 '22 08:09

FRAGA