javascript - CSS 侧边栏菜单溢出
问题描述
当我为侧面导航栏添加文本时,文本将溢出到下一行,而不是继续在同一行上。例如,我希望 CRF 注释和 CRI 注释不会像当前那样溢出。我不确定我错过了什么。我尝试将显示更改为内联块,但没有奏效。我弄乱了 CSS 页面中的某些宽度。我确定我只是忽略了某些东西,但无法弄清楚。
这是导航菜单的html
<div class="w3-sidebar w3-bar-block w3-card w3-animate-left" style="display:none" id="mySidebar">
<button class="close_button"
onclick="w3_close()">Close</button><br />
<a href="default.aspx" class="w3-bar-item w3-button">Home</a> <br />
<a href="application.aspx"class="w3-bar-item w3-button">Application</a><br />
<a href="vehicle.aspx"class="w3-bar-item w3-button">Vehicle</a><br />
<a href="AddOn.aspx" class="w3-bar-item w3-button">NADA</a><br />
<a href="visa.aspx"class="w3-bar-item w3-button">Visa</a><br />
<a href="AppNotes.aspx" class="w3-bar-item w3-button">CRF Notes</a><br />
<a href="CritNotes.aspx" class="w3-bar-item w3-button">CRI Notes</a><br />
</div>
<div id="main">
<div class="w3-teal">
<button id="openNav" class="w3-button w3-teal w3-xlarge" onclick="w3_open()">Navigation</button>
<div class="w3-container">
</div>
</div>
</div>
</nav>
这是打开和关闭按钮的脚本
<script>
function w3_open() {
document.getElementById("main").style.marginLeft = "5%";
document.getElementById("mySidebar").style.width = "5%";
document.getElementById("mySidebar").style.display = "block";
document.getElementById("openNav").style.display = "none";
}
function w3_close() {
document.getElementById("main").style.marginLeft = "0%";
document.getElementById("mySidebar").style.display = "none";
document.getElementById("openNav").style.display = "inline-block";
}
</script>
这是我的CSS
body{
font-family: Verdana, Arial, sans-serif;
background-color: #eff6ee;
display:block;
position:absolute;
height:auto;
bottom:0;
top:0;
left:0;
right:0;
margin-top:0px;
margin-bottom:00px;
margin-left:0px;
margin-right:0px;
}
#wrapper {
background-color: white;
width: auto;
height:100%;
overflow:hidden;
margin-left: 36px;
}
nav {
float: left;
width: 80px;
padding-top:50px;
padding-right:55px;
background-color:#2e3532;
height:100%;
}
#rightcol {
margin-left: 100px;
background-color: #eff6ee;
color: #000000;
height:100%;
}
header {
background-color: #9197ae;
font-size: 100%;
padding-left: 30px;
padding-bottom:5px;
padding-top:3px;
}
h1{
padding-top:10px;
text-shadow: -2px 0 #f00,0 2px #f00, 2px 0 #f00, 0 -2px #f00;
color:#eff6ee;
margin-left:135px
}
h2 {
color: #869dc7;
font-family: arial, sans-serif;
}
main {
display:flex;
padding: 20px 20px 20px;
}
#floatright {
margin: 10px;
float: right;
}
nav a {
margin: 30px;
color:#9197ae;
}
nav a:visited{
color:mediumpurple;
}
nav a:hover{
color:white;
text-decoration:underline;
}
.close_button{
width:125px;
text-align:center
}
#openNav{
width:125px;
text-align:center
}
.logo{
padding-left:10px;
padding-right:10px
}
.ssninput{
background-color:#eff6ee;
padding-left:10px
}
.table{
padding-left:10px
}
解决方案
您正在为缩小它的 nav 元素提供填充权,并且还通过 js 将 div 宽度设置为 5%,这应该是 100%。
希望这个小提琴可以帮助你。
nav {
float: left;
width: 150px;
padding-top:50px;
/*padding-right:55px;*/
background-color:#2e3532;
height:100%;
}
function w3_open() {
document.getElementById("main").style.marginLeft = "5%";
//document.getElementById("mySidebar").style.width = "5%";
document.getElementById("mySidebar").style.width = "100%";
document.getElementById("mySidebar").style.display = "block";
document.getElementById("openNav").style.display = "none";
}
function w3_close() {
document.getElementById("main").style.marginLeft = "0%";
document.getElementById("mySidebar").style.display = "none";
document.getElementById("openNav").style.display = "inline-block";
}
推荐阅读
- ubuntu - 如何使用 SNAP 安装 VSCode?ERROR= snap-confine 具有提升的权限
- git - 在集成 Jenkins 时我是否应该在 GIT 中有多个发布分支
- sql - SQL 查询返回 ID、办公室编号以及每年是否有该员工的发票
- codenameone - 代号一中从视频到图像
- php - 如何在 Laravel 6 中使用动态字段返回视图
- pandas - 使用 Pandas 的堆积条形图
- android - Android TV 无法访问互联网
- angular - 当另一个组件的输入值发生变化时,调用另一个组件的方法
- jquery - 如何在反应代码中转换这个 jQuery?
- c# - 连接到不安全的 gRPC 通道时“响应提前结束”