gpt4 book ai didi

html - CSS:菜单没有定位到右侧?

转载 作者:太空宇宙 更新时间:2023-11-04 06:27:12 24 4
gpt4 key购买 nike

我尝试了所有我知道的方法,但我的汉堡菜单图标就是不想移到右边...有谁知道到底是什么让它留在左边?

我也在使用 SemanticUI。

这是我的代码:https://jsfiddle.net/657pxedq/5/

HTML:

<div id="navbar">
<div class="openbtn" onclick="openNav()"><i class="bars icon"></i></div>
</div>

<script>
function openNav() {
document.getElementById("mySidebar").style.width = "250px";
document.getElementById("main").style.marginRight = "250px";
document.getElementById("dimmer").style.display = "block";
}

function closeNav() {
document.getElementById("mySidebar").style.width = "0";
document.getElementById("main").style.marginRight = "0";
document.getElementById("dimmer").style.display = "none";
}
</script>

<script>
window.onscroll = function() {myFunction()};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;

function myFunction() {
if (window.pageYOffset >= sticky) {
navbar.classList.add("sticky")
} else {
navbar.classList.remove("sticky");
}
}
</script>

CSS:

.openbtn {
font-size: 20px;
cursor: pointer;
color: #744a84;
padding: 10px 15px;
border: none;
background-color: transparent;
right: 0;
justify-content: right;
float: right;
text-align: right;
}

#navbar {
position: fixed;
overflow: hidden;
background-color: transparent;
display: flex;
justify-content: right;
width: 100%;
z-index: 2;
text-align: right;
}

.sticky {
position: fixed;
top: 0;
width: 100%;
}

(呃,由于代码太多,Stackoverflow 希望我添加更多细节......但我不知道该说些什么)

提前致谢!

最佳答案

汉堡包菜单可以通过添加 position:fixed 固定在右边

.openbtn {
font-size: 20px;
cursor: pointer;
color: #744a84;
padding: 10px 15px;
border: none;
background-color: transparent;
right: 0;
justify-content: right;
position: fixed;
text-align: right;
}

更新的 JSFiddle - https://jsfiddle.net/q2svn48p/

关于html - CSS:菜单没有定位到右侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54969977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com