简体   繁体   English

CSS图像背景和叠加阻止链接和文本输入单击和焦点

[英]CSS image background and overlay blocking link and text input click and focus

I have the following html and css: 我有以下html和css:

 .icon-bar { width: 90px; z-index: 100; position: absolute; } #overlay { position: absolute; background-color: rgba(0,0,0,0.8); top:0; left: 0; bottom:0; height:100%; width:100%; z-index: -2; } #cover-photo { width:100%;height: 400px; background:url('./assets/covers.jpg') no-repeat center center fixed; color:#fff; background-size:cover; text-align: center; z-index: -1; } 
  <div class="row"> <div class="col-md-12" id="cover-photo"> <div id="overlay"> </div> <div class="icon-bar col-md-push-10"> <a class="active" href="#"><i class="fa fa-home"></i></a> <a href="#"><i class="fa fa-search"></i></a> <a href="#"><i class="fa fa-envelope"></i></a> <a href="#"><i class="fa fa-globe"></i></a> <a href="#"><i class="fa fa-trash"></i></a> </div> </div> </div> 

Now the background image is appearing, as well as the overlay div as expected, the div with the icon-bar class also appears in the front, but when I try to click one of the links inside that div it does not get the click, i have set a z-index of 100 for this div but it is unclickable, please assist me on this guys 现在出现背景图像,以及预期的叠加div,带有图标栏类的div也出现在前面,但是当我尝试单击该div中的一个链接时,它没有得到点击,我为这个div设置了一个z-index为100,但它是不可点击的,请帮助我这个家伙

You can add pointer-events: none to the overlay div. 您可以将overlay pointer-events: none添加到overlay div中。 This will allow clicking the links behind it. 这将允许单击它后面的链接。

I think it is because of anchor tag it is inline tag 
try to make it inline-block so it will work.

Check below link

https://jsfiddle.net/ashishbhalerao/Ldot4y96/4/

Thanks,

Ashish Bhalerao

I think I got your point here. 我想我明白了你的观点。 What's wrong in your code is where you position <div id="overlay"></div> 您的代码中出现的问题是您将<div id="overlay"></div>置于何处

It should place after the end tag of cover-photo 它应该放在cover-photo的结束标记之后

I also rearrange your codes and modify some it. 我也重新安排你的代码并修改它。

My advise is not to make to have negative z-index instead use smaller to greater number to overlap the property of one element to another. 我的建议是不要使用负z-index而是使用更小到更大的数字来重叠一个元素与另一个元素的属性。

 #cover-photo { width: 100%; height: auto; background: url('./assets/covers.jpg') no-repeat center center fixed; color: #fff; background-size: cover; text-align: center; z-index: 5; } .icon-bar { width: 90px; z-index: 100; position: relative; } #overlay { position: fixed; background-color: rgba(0, 0, 0, 0.8); top: 0; left: 0; bottom: 0; height: 100%; width: 100%; z-index: 1; } 
 <div class="row"> <div class="col-md-12" id="cover-photo"> <div class="icon-bar col-md-push-10"> <a class="active" href="#"><i class="fa fa-home"></i></a> <a href="#"><i class="fa fa-search"></i></a> <a href="#"><i class="fa fa-envelope"></i></a> <a href="#"><i class="fa fa-globe"></i></a> <a href="#"><i class="fa fa-trash"></i></a> </div> </div> <div id="overlay"></div> </div> 

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

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