Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have a non-clickable section of a link?

Tags:

html

css

Hopefully simple enough, in the below example I want the blue section of the link to be clickable (as a link) but the red section not to be. I am planning to subscribe to the red section's onclick event after with Javascript.

Spent an hour on this and getting nowhere! Does anybody know how to do this?

.outer{
    width:300px;
    height:50px;
    background-color:blue;
    position:relative;
    display:block;
    color:white;
    z-index:1;
}

.inner{
    width:150px;
    height:25px;
    background-color:red;
    top:0;
    right:0;
    position:absolute;
    pointer-events:none;
    z-index:2;
}
<a href="http://google.co.uk" class="outer">
    Clickable
    <div class="inner">
        Not clickable
    </div>
</a>

I thought the inner div having a higher z-index and no pointer events would do it, but doesn't seem to work.

Anybody have any ideas?

like image 481
JMK Avatar asked Dec 03 '25 17:12

JMK


1 Answers

Instead of hacking the html like that, which is a very bad practice. Why not:

.outer {
  background-color: red;
  display: inline-block;
}

.inner {
  background-color: blue;
  width: 300px;
  display: inline-block;
}

span {
  display: inline-block;
}
<div class="inner">
  <a href="http://google.co.uk" class="outer">Clickable</a>
  <span>Not clickable</span>
</div>
like image 135
Vlad Avatar answered Dec 10 '25 09:12

Vlad