![](/img/trans.png)
[英]Navigation bar jumping to the right when position fixed is added with js, trying to compensate with width(calc), but open side navigation breaks it
[英]I was trying to make side navigation bar open with a checkbox but when I check the box the side bar doesn't appear
有什么想法我哪里出錯了嗎? 我嘗試在 CSS 內將寬度設置為 0 並使用 JavaScript 添加寬度它仍然沒有用。
function showsidenav(){ document.getElementsById("barres").style.display = "block"; }
.opened-side-nav { background-color: ghostwhite; width: 30%; height: 100%; position: absolute; border-right: black 2px solid; z-index: 1; overflow: hidden; display: none; }
<!--Nav Bar--> <div class="opened-side-nav" id="barres">Content</div> <div class="logo"> <input id="5055" class="showsidenavbar" type="checkbox" onclick="showsidenav()"> <label for="5055">=</label> </div> </div>
使用getElementById
而不是getElementsById
。 對於 id,Element 中沒有“s”。 拼寫中的“s”是導致它的原因,也就是說,如果您的代碼工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.