javascript - 设置 width : 0 不隐藏文本
问题描述
我想创建一个侧面导航菜单。这在大屏幕上可见,在小屏幕上隐藏,并在调用 javascript 函数以取消隐藏时变得可见。
一切都按预期工作,但是即使将宽度设置为 0,内容也没有隐藏;文本仍然可见。
@media screen and (max-width: 768px)
{
.mysidebar
{
height: 100%;
width: 0px;
position: fixed;
z-index: 15;
top: 0;
left: 0;
background-color: #405a84; /
overflow-x: hidden;
padding-top: 10px;
transition: 0.5s;
padding-right: 0px !important;
padding-left: 0px !important;
text-overflow : hidden;
}
}
@media screen and (min-width: 768px)
{
.mysidebar
{
width : 16%;
height : 100%;
display : inline-block;
float : left;
}
.rightmainpane
{
width : 84%;
height : auto;
display : inline-block;
}
}
<div class="mysidebar" id="mySidenav">
Some sample content that is not hiding on small screen as expected, but the
background color etc are hiding.
</div>
<div class="rightmainpane" id="rightmainpane">
Some ok content that should be visible
</div>
使用此 javascript 代码隐藏/显示 id="mySidenav" div
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("mySidenav").style.width = "0";
设置显示:none/block 正在解决问题。但是它没有显示过渡,显示和隐藏过渡对我来说非常重要。
请帮忙。谢谢你。
解决方案
当您将宽度设置为 0 时,overflow: hidden
您的容器上也有。
推荐阅读
- javascript - 根据属性显示排序的 Json 数据
- jsf - 如何使 inputText 预输入值像 jsf/bootsfaces 中的按钮一样可点击?
- android - 实现 setState 导致 Infinite Loop Flutter
- rust - 数字数组(不是 Vec)的类型是什么?
- angular - Angular:如何检查服务中的布尔值是否已更新?
- android - 在 Windows Linux 子系统上,Android SDK 目录不存在
- javascript - 将 Javascript 和 PHP 结合在一起
- macos - Zsh 启动错误,brew 更新后
- mysql - MYSQL 抛出一个语法错误
- python - 无法从不存在的 easy-install.pth 文件中删除条目