简体   繁体   English

当我在其中添加“空格”时,如何确保文本保持在同一行 <li> 元件?

[英]How do I make sure my text stays on same line when I add a 'space' inside <li> element?

I constantly find myself browsing SOF and have yet to post so here it is. 我经常发现自己在浏览SOF,并且还没有发布,所以就在这里。 I'm building a new website and am a relative beginner to CSS. 我正在建立一个新网站,并且是CSS的相对入门者。 I am struggling with a basic nav menu and just can't quite research how to solve a problem.. 我正在用基本的导航菜单苦苦挣扎,只是不能完全研究如何解决问题。

Here is my website and if you look under the 'Contact dropdown you'll see that the first list item is on 2 lines when I want it on only one like what you see under the 'Downloads' drop down. 这是我的网站 ,如果您在“联系人”下拉列表下浏览,您会发现第一个列表项位于两行,而我只希望在“下载”下拉列表中看到该列表项。

In case anyone wants the code 万一有人想要代码

.nav{
width:100%;
background-color: #0066B9;
font-family: verdana;
font-weight: bold;
padding-top: 4px;
padding-bottom: 4px;
max-height: 31px;
}
.nav ul{
top: 0;
width:960px;
margin:0 auto;
list-style: none;
padding-left: 0px;
display: inherit;
}
.nav li{
display: inline;
position: relative;
background-color: #003E64;
padding-top: 4px;
padding-bottom: 4px;
}
.nav ul li a{
color: white;
text-decoration: none;
padding: 10px;
line-height: 21px;
}
.nav ul li a:hover{
background-color: purple;
color: black;
padding-top: 4px;
padding-bottom: 4px;
}
.nav ul li ul{
display: none;
position: absolute;
margin: 0px;
background-color: #003E64;
width: auto;
}
.nav ul > li > ul{
position: absolute;
left: 0;
margin-top: 27px;
display: none;
padding-top: 10px;
overflow: hidden;
}
.nav ul li:hover > ul{
display: block;
padding-left: 6px;
}
.nav ul > li > ul > li{
position: relative;
display: block;
width: auto;
}
.nav ul > li > ul > li a{
padding: 10px;
}

Apologies in advance if I posted incorrectly. 如果我发帖不正确,请提前致歉。 Not exactly sure what it's asking me to indent by 4 spaces. 不确定我要缩进4个空格是什么。

Try using the white-space CSS property: 尝试使用white-space CSS属性:

.nav li {
    ...
    white-space: nowrap;
}

https://developer.mozilla.org/en-US/docs/Web/CSS/white-space https://developer.mozilla.org/zh-CN/docs/Web/CSS/white-space

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM