简体   繁体   English

我无法将导航栏文本链接设置为水平吗?

[英]I can't make my navigation bar text links horizontal?

I have spent a while trying to find out how to make text links sit horizontally on a navigation bar, but to no success.I am EXTREMELY new to coding so this is probably extremely easy to do, i am using html and CSS, i have tried just putting them on the same line. 我花了一段时间尝试找出如何使文本链接水平放置在导航栏上,但没有成功。我对编码非常陌生,所以这可能非常容易做到,我正在使用html和CSS,尝试将它们放在同一行上。 Also using: 还使用:

#nav li a {
    color: black;
    display: inline;
    list-style-type: none;
}

#nav li a {
    color: black;
    position: relative; 
}

i have tried to find the answer on the site but i cant see one, so i thought i might as well just ask people. 我试图在网站上找到答案,但是我看不到答案,所以我认为我不妨问问人们。 Thank you for reading. 感谢您的阅读。

You are targeting the wrong element, it should be 您定位的元素错误,应该是

#nav li {
   display: inline;
}

You were selecting a element, you need to target the li , a is an inline element by default, li renders one below the other, so to make them inline, we target li 您正在选择a元素,您需要定位li ,默认情况下a是一个inline元素, li会在另一个元素下方渲染,因此要使其内联,我们将li

I would suggest you to use 我建议你用

#nav li {
   display: inline-block;
   margin-left: -4px; /* If that white space matters to you */
}

As you will get same effect, but with some additional bonus like margins padding to space up your element. 您将获得相同的效果,但还有一些额外的好处,例如margins padding可以间隔您的元素。 Alternatively, you can also use float: left; 另外,您也可以使用float: left; but you will need to clear your floats so stick with inline-block 但您需要clear浮子,所以要坚持使用inline-block

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

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