简体   繁体   English

如何在div下方点击链接

[英]How to make a link beneath a div clickable

I have a link under a div with 100% height and width in a fixed position and z-index: 5. I need to keep this div above my link, but the link doesn't work. 我在一个div下的链接具有固定高度和100%高度和宽度的z-index:5.我需要将该div保持在链接上方,但是该链接不起作用。 Can I make the link work but keep this div above my link? 我可以使链接正常工作,但可以将该div保持在链接上方吗?

https://jsfiddle.net/8hu90e9x/1/ https://jsfiddle.net/8hu90e9x/1/

 div { background:grey; width:100%; height:100%; position:fixed; top:0; opacity:0.5; z-index:5 } a { font-size:50px; z-index:0 } 
 <a href="http://google.com"> My link</a> <div></div> 

You could add pointer-events:none; 您可以添加pointer-events:none; to the CSS rules for your div div的CSS规则

 div { background:grey; width:100%; height:100%; position:fixed; top:0; opacity:0.5; z-index:5; pointer-events:none; } a { font-size:50px; z-index:0; } 
 <a href="http://google.com"> My link</a> <div></div> 

If the purpose of this div is just to change the background color, it would be easier to delete it and do this instead: 如果此div的目的仅仅是更改背景颜色,则将其删除并执行以下操作会更容易:

body{
    background-color:lightgrey;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM