This is my HTML (simplified) and CSS:
div {
border: 2px solid red;
width: 200px;
height: 200px;
}
img {
z-index: 0;
}
#plate {
position: absolute;
left: 20px;
top: 30px;
opacity: 0.7;
z-index: 10;
}
<div>
<a href="https://google.com">
<img src="https://placehold.it/200/333333" />
<img id="plate" src="https://placehold.it/100/999999" />
</a>
</div>
The result can be seen here:
https://jsfiddle.net/fcsyrz2h/
How to change the CSS code so that id="plate"
rectangle is not clickable (so that we don’t go to the href
of <a>
).
PS. The rest area of <a>
other than the <img id="plate">
should be clickable.
P.P.S The question improved.
3
Answers
If you move the second
id="plate"
image that you don’t want to be clickable outside of the anchor tag, it should work.Based on this answer, you can add pointer-events: none;
I understand that you want to achieve this effect via CSS presentation.
But it is a category of problem which can only be achieved via HTML structure.
i.e. you need to think about structure and about which elements should be parents, which should be children and which should be siblings.
You can punch a hole in the
<a>
element.But if you do, then
#plate
will no longer be there.Because
#plate
is a child of the<a>
– and you’ve just punched a#plate
-sized hole right out of the<a>
.Example: