html - How can I create a create a hole within a DIV? -


this question has answer here:

so have following html structure:

<canvas></canvas> <div class="overlay">     <button>click me!</button> </div> 

the canvas absolutely positioned negative z index, overlay positioned on (i have working). issue want overlay div have white background, button have transparent background , show through canvas/body background color.

background-color:rgba(0,0,0,0);  

doesn't work because shows white background behind it. ideas on how accomplish effect?

the question may have been marked potential duplicate of fails account fact buttons can have properties such border-radius , offers no suitable solutions.

there's no way create hole inside html element. transparent background can applied element not descend parent has non-transparent background.

what do, thought it's little bit more complicate, create divs around button, @ it's same level, siblings. give divs white background, , transparent button should work.

i've created sample using table layout, button remains in middle row, in center cell. see button reveals canvas background color:

canvas {      width: 200px;      height: 200px;      background: purple;      position: absolute;      z-index: -1;  }    .overlay {      width: 200px;      height: 200px;      display: table;  }    .overlay button {      background-color: transparent;      white-space: nowrap;  }    .overlay > div {      display: table-row;  }    .overlay > .middle {      height: 1px;  }    .overlay > div > div {      display: table-cell;      text-align: center;  }    .overlay > .middle > div:nth-child(2) {      width: 1px;  }    /* now, set background on divs around button */  .top, .left, .right, .bottom {      background: white;  }
<canvas></canvas>  <div class="overlay">      <div class="top">          <div></div>          <div></div>          <div></div>      </div>      <div class="middle">          <div class="left"></div>          <div>              <button>click me!</button>          </div>          <div class="right"></div>      </div>      <div class="bottom">          <div></div>          <div></div>          <div></div>      </div>  </div>


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -