0

I have two full screen divs stacked.

css

#border-overlay {
    position:absolute;
    z-index: 100;
    top:0; left:0;
    width: 100vw;          
    height: 100vh;
    box-sizing: border-box; 
    border: solid 8px white;
}

#button
    position: absolute;
    display: block;
    top: 0; left: 0;
    height: 100%; width: 100%;
    background-color: rgba(0,0,0,0);
    z-index: 15;
}

html

<div id="border-overlay"></div>
<a id="button" href=""> ... </a>

I need the border div on top the button div, however this removes the link function of the button which I want to keep. Essentially the button takes up the full screen so you can click anywhere.

user3550879
  • 3,389
  • 6
  • 33
  • 62

2 Answers2

0

Not 100% sure what you are trying to achieve but you can do the following:

Insert onclick event to your wrapper div that will call click of your anchor tag. Also add to css the pointer cursor and it will look like you press on the anchor.

function clickMe() {
  document.getElementById("button").click();
}
#border-overlay {
    position:absolute;
    z-index: 100;
    top:0; left:0;
    width: 100vw;          
    height: 100vh;
    box-sizing: border-box; 
    border: solid 8px white;
    background-color: yellow;
    cursor: pointer;
}

#button{
    position: absolute;
    display: block;
    top: 0; left: 0;
    height: 100%; width: 100%;
    background-color: rgba(0,0,0,0);
    z-index: 15;
}
<div id="border-overlay" onclick="clickMe()"></div>
<a id="button" href="/asdad"> Link me up Scottie</a>
Ziv Weissman
  • 4,400
  • 3
  • 28
  • 61
0

No JavaScript needed. Use the CSS pointer-events: none on the div:

#border-overlay {
  position: absolute;
  z-index: 100;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  box-sizing: border-box;
  border: solid 8px white;
  pointer-events: none;
}

jsFiddle example

j08691
  • 204,283
  • 31
  • 260
  • 272