2013-05-27 39 views
10

我有一個頁面上的菜單和絕對定位的div。問題是,當這個div在一個頁面上時,我無法點擊菜單項中的任何鏈接。當絕對位置的div添加不能點擊鏈接

當我刪除這個div(#left_border),然後鏈接可以再次點擊。

爲什麼?

CSS:

#left_border { 
    background-image: url(http://tax.allfaces.lv/templates/tax/images/ena.png); 
    background-position: 0 0; 
    background-repeat: no-repeat; 
    width: 1094px; 
    background-size: 100% auto; 
    position: absolute; 
    height: 850px; 
    left: -51px; 
    top: 0px; 
} 

HTML:

<div id="wrapper"> 
<div id="content"> 
    <div id="left_border"></div> 
    <div id="left"> 
     <div id="menu"> 
      <ul class="menu"> 
       <li class="item-101 current active deeper parent"><a href="/">Home</a> 

        <ul> 
         <li class="item-107"><a href="/index.php/home/news">News</a> 

         </li> 
        </ul> 
       </li> 
       <li class="item-102 deeper parent"><a href="/index.php/merchants-shops">Merchants/Shops</a> 
       </li>      
      </ul> 
     </div> 
    </div>  
</div> 

這裏你可以看到,你不能點擊菜單項:http://jsfiddle.net/Dq6F4/

回答

0

使用谷歌瀏覽器或Mozilla Firefox的開發者工具,懸停在鏈接和申報單(或選擇它們)。通過這種方式,您可以看到發生了什麼,最有可能的是,還有另一個div或其他對象疊加在鏈接上,這會阻止您點擊它們。 火狐還擁有3D選項,可視化這一切甚至更好:

https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/3D_view 
12

添加z-index:-1;這將允許被點擊的鏈接。由於該部門絕對定位在鏈接上,因此不允許可點擊性。

#left_border { 
    background-image: url(http://tax.allfaces.lv/templates/tax/images/ena.png); 
    background-position: 0 0; 
    background-repeat: no-repeat; 
    width: 1094px; 
    background-size: 100% auto; 
    position: absolute; 
    height: 850px; 
    left: -51px; 
    top: 0px; 
    z-index:-1; 
} 

這裏是Working Solution爲相同。

希望這有助於。

2

你必須用z-index問題..

它是覆蓋菜單元素:

#left_border { 
    background-image: url(http://tax.allfaces.lv/templates/tax/images/ena.png); 
    background-position: 0 0; 
    background-repeat: no-repeat; 
    width: 1094px; 
    background-size: 100% auto; 
    position: absolute; 
    height: 850px; 
    left: -51px; 
    top: 0px; 
    z-index:-111; 
} 

http://jsfiddle.net/Dq6F4/2/

0

你的問題其實是#left_border覆蓋鏈接作爲覆蓋。限制它的寬度......

#left_border{ 
    width:50px; 
} 
6

疏通點擊添加到#left_border css類聲明如下:

CSS

pointer-events: none 

(它是跨瀏覽器解決方案,包括> = IE11)

此溶液與Here is source更多信息。我在Chrome,Firefox和safari(macOs和iOS)上測試它,並且工作:)