41

I have menu on a page and div that is absolute positioned. The problem is that when this div is on a page, then I cannot click on any links in menu items.

When I remove this div (#left_border), then links are clickable again.

Why?

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>

Here you see, that you cannot click on menu items: http://jsfiddle.net/Dq6F4/

renathy
  • 4,686
  • 17
  • 79
  • 136

9 Answers9

71

CSS - to unblock clicking add to #left_border class following statement:

pointer-events: none 

(it is cross-browser solution including >= IE11)

Here is source of this solution with more informations. I tested it on chrome, firefox and safari (macOs and iOS) and works :)

If you like this answer buy me a coffee

Kamil Kiełczewski
  • 71,169
  • 26
  • 324
  • 295
24

Add a z-index:-1; This will allow the links to be clicked. As The Div is absolutely positioned over the links and hence it is not allowing clickability.

 #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;
}  

Here is the Working Solution for the same.

Hope this Helps.

Nitesh
  • 15,091
  • 4
  • 44
  • 55
  • 1
    While this might've worked years ago, this solution is no longer applicable. `z-index: -1` is a hack and using it will never work over time. As you can see today, elements with `z-index: -1` no longer show up in Chrome. The preferred solution is `pointer-events: none`. – Kevin Ghadyani Jun 12 '19 at 23:02
6

put z-index:1 to that component which has absolute property.

for example:

function myFunction() {
  document.getElementById("print").innerHTML = "Hello World";
}
.custcontainer {
    position: relative;
    
}
.custcontainer .like {
    position: absolute;
    top: 18%;
    left: 10%;
    transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);

    cursor: pointer;
    font-size:30px;
    text-align: center;
    z-index: 1;
}
<div class="custcontainer">
  <P id="print"></p>
  <button onclick="myFunction()" class="like">like</button>
  <img src="https://www.crownplumbing.co/wp-content/uploads/2015/07/placeholder.gif"/>
</div>
Aditya Parmar
  • 989
  • 11
  • 21
5

Add position:relative to #menu

#menu
{
    position:relative;
}

JS Fiddle Demo

Sachin
  • 39,043
  • 7
  • 86
  • 102
3

you have a problem with z-index..

it is covering the menu elements:

 #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/

Dory Zidon
  • 10,132
  • 2
  • 23
  • 37
1

Your problem is actually with #left_border covering the links as overlay. limit it's width.. e.g.

#left_border{
  width:50px;
}
Yotam Omer
  • 14,836
  • 11
  • 58
  • 62
0

Use Google Chrome or Mozilla Firefox's Developer tools to hover over your links and divs (or select them). This way you can see what is going on, and most probably, there is another div or other object stacked on top of your links, which is preventing your from clicking them. Firefox also has a 3D option, which visualizes all this even better:

https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/3D_view
Borniet
  • 3,516
  • 4
  • 22
  • 33
0

I found a very simple solution that works!I set the left to a percentage-it was in pixels- and added a margin-left in pixels.And that worked like a charm!! http://2letscode.blogspot.com/2014/07/links-not-clickable-when-inside.html

  • Please don't just post a link but describe and demonstrate how it helps to solve the problem. –  Jul 31 '14 at 11:09
0

Z-index only works on positioned elements. A positioned elements is an element whose position value is either set to absolute, fixed, relative, or sticky. That is, the element has to be set to any position value other than static, which is the default position value. See this article

Alex Cory
  • 8,820
  • 7
  • 47
  • 60