gpt4 book ai didi

javascript - CSS、HTML : Sidebar with animation as 1 button not as 2

转载 作者:行者123 更新时间:2023-11-28 01:56:21 26 4
gpt4 key购买 nike

我有一个带有打开菜单的按钮“M”的侧面菜单,但是当打开菜单而不是 10 个按钮时,我得到 20 个像 B-Button,B 是图像,Button 是文本。当菜单打开时,它们需要是同一个按钮而不是 2 个单独的按钮,我知道它们被编码为 2 个单独的按钮但是我应该朝什么方向使它们只有在菜单打开时才成为 1 个按钮

代码:

 function MenuButton() {
if (document.getElementById("mySidenav").style.width == "150px")
{
document.getElementById("mySidenav").style.width = "0px";
}
else {
document.getElementById("mySidenav").style.width = "150px";
}
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
top: 34px;
left: 49px;
z-index: 2;
background-color: #111;
overflow: hidden;
transition: 0.5s;
padding-top: 55px;
}

.sidenav a {
font-style: normal;
font-variant-ligatures: normal;
font-variant-caps: normal;
font-variant-numeric: normal;
font-weight: normal;
font-stretch: normal;
font-size: 25px;
line-height: 1;
padding: 8px 8px 8px 15px;
text-decoration: none;
display: block;
color: white;
transition: 0.3s;
white-space: nowrap;
}

.sidenav a:hover {
background-color: #3498db;
}

.buttons {
height: 100%;
width: 50px;
position: fixed;
margin: 0 auto;
top: 34px;
left: 0;
z-index: 1;
background-color: #111;
overflow: hidden;
transition: 0.5s;
padding-top: 14px;
}

.buttons a{
font-style: normal;
font-variant-ligatures: normal;
font-variant-caps: normal;
font-variant-numeric: normal;
font-weight: normal;
font-stretch: normal;
font-size:25px;
line-height: 1;
padding: 8px 8px 8px 15px;
text-decoration: none;
color: white;
display: block;
transition: 0.3s;
cursor: pointer;
}

.buttons a:hover{
background-color: #3498db;
}
<div id="mySidenav" class="sidenav">
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
</div>

<div id="buttonside" class="buttons">
<a><span onclick="MenuButton()">M</span></a>

<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
<a>B</a>
</div>

JSFiddle Link

最佳答案

尝试将您的图标或图像包装成具有如下宽度的span

function MenuButton() {
if (document.getElementById("buttonside").style.width == "150px") {
document.getElementById("buttonside").style.width = "50px";
} else {
document.getElementById("buttonside").style.width = "150px";
}
}
.sidenav {
background-color: #111;
overflow: hidden;
transition: 0.5s;
}

.sidenav a:hover {
background-color: #3498db;
}

.buttons {
width: 50px;
background-color: #111;
overflow: hidden;
transition: 0.5s;
padding-top: 14px;
}

.buttons a {
font-size: 25px;
line-height: 1;
padding: 8px 0px;
text-decoration: none;
color: white;
display: block;
transition: 0.3s;
cursor: pointer;
white-space: nowrap;
}

.buttons a span {
width: 50px;
display: inline-block;
text-align: center;
}

.buttons a:hover {
background-color: #3498db;
}
<div id="buttonside" class="buttons">
<a onclick="MenuButton()"><span>M</span></a>
<div id="mySidenav" class="sidenav">
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
<a><span>B</span>Link</a>
</div>
</div>

关于javascript - CSS、HTML : Sidebar with animation as 1 button not as 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49605292/

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