html - Open a div by clicking a button, close the div by clicking outside only with CSS -


i have button opens , closes div. improve feature: want div close when pressing other on div. possible in css , html?

it's button 'top-bar-btn settings' :

edit

<div class="top-bar-btn" id="top-bar-btn">   <button class="top-bar-btn create"           title="créer une nouvelle discussion">           <!--(click)="oncreatechatwindow()">-->     <i class="glyphicon glyphicon-edit"></i>   </button>     <button class="top-bar-btn settings"           title="réglages"           (click)="onsettingschatwindow()">     <i class="glyphicon glyphicon-cog"></i>   </button>   <div id="outside" (click)="hide()"></div>    <button class="top-bar-btn reduce"           title="réduire la fenêtre"           (click) = "onreducechatthreads()">     <i class="glyphicon glyphicon-minus"></i>   </button> </div> 

 <div class="settings-notification"    id="settings-notification"> <div class="tr triangle">   <div class="tr inner-triangle">   </div> </div> <div class="sound-signal">   signal sonore :   <input type="radio" name="soundsignal" id="soundsignal1" checked="checked">   <label for="soundsignal1">oui</label>   <input type="radio" name="soundsignal" id="soundsignal2">   <label for="soundsignal2">non</label> </div>  <div class="flash-signal">   signal visuel :   <input type="radio" name="flashsignal" id="flashsignal1" checked="checked" (click)="flashsignal()">   <label for="flashsignal1">oui</label>   <input type="radio" name="flashsignal" id="flashsignal2" (click)="notflashsignal()">   <label for="flashsignal2">non</label> </div> 

>

#outside{ display:none; height:100%; width:100%; position:fixed; top:0px; left:0px; z-index:1; }   hide(): void {     document.getelementbyid('outside').style.display = 'none';     document.getelementbyid('settings-notification').style.display = 'none'; }  onsettingschatwindow(): void {     document.getelementbyid('outside').style.display = 'block';     document.getelementbyid('chat-threads').classlist.toggle('display-settings'); } 

i not understand why not work. works once , after div no longer displays @ all. know why ?

you can't show/hide, move... objects using css or html only. can use javascript. make 2 divs display:none; 1 div want show, , 1 background(width , height 100%, z-index less div want show/hide more other element, , position:fixed;) inside div represents background add onclick="hide()" , call function hide() whenever click outside div. , add function hide() make both div-s disappear.

function myfunction(){  document.getelementbyid("outside").style.display = "block";  document.getelementbyid("mydiv").style.display = "block";  }    function hide(){  document.getelementbyid("outside").style.display = "none";  document.getelementbyid("mydiv").style.display = "none";  }
#outside{  display:none;  height:100%;  width:100%;  position:fixed;  top:0px;  left:0px;  z-index:1;  }    #mydiv{  background:red;  width:300px;  height:100px;  position:absolute;  top:100px;  left:100px;  display:none;  z-index:2;  }
<button onclick="myfunction()">show div</button>  <p><span>some text</span></p>  <p><span>some text</span></p>  <p><span>some text</span></p>  <p><span>some text</span></p>  <p><span>some text</span></p>  <div id="outside" onclick="hide()"></div>  <div id="mydiv"></div>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -