javascript - Child div not disappearing with visibility hidden -
my code involves having div in div, , when set both of visibilities hidden, parent div disappears. in debugging attempt, tried print out visibility of child div, , has 'visibility: hidden'.
#popup { visibility: visible; margin: auto; position: fixed; background-color: black; padding-top: 5px; padding-bottom: 5px; padding-left: .5%; padding-right: .5%; border-radius: 4px; left: 14.5%; top: 20px; width: 70%; height: 450px; } #redx { visibility: visible; position: absolute; right: 0px; top: 0px; width: 35px; height: 35px; text-align: center; font-size: 25px; font-weight: bold; color: white; background-color: red; transition: .2s color ease-out; } ------------------------------------------------ // how control styles in changepopupvisibility() var popup = document.getelementbyid('popup'); var redx = document.getelementbyid('redx'); var popupopen = true; ------------------------------------------------ // rx variable use paste redx in different functions. var rx = "<div id='redx' onclick='changepopupvisibility()'>x</div><br>"; ------------------------------------------------ // how change visibility when x has been clicked function changepopupvisibility() { popupopen = !popupopen; if (popupopen) { redx.style.visibility = "visible"; popup.style.visibility = "visible"; } else { redx.style.visibility = "hidden"; popup.style.visibility = "hidden"; } }
in case gets little confusing, i've put working version of mean on my website. click red x once , disappear, click word "left" , try again , parent disappear.
thanks.
you should use: display: none;
makes element not displayed @ , has no effect on layout, visibility: hidden;
element invisible still occupies space in layout.
read:
and more specifically:
Comments
Post a Comment