简体   繁体   English

垂直导航栏无法正常工作

[英]Vertical Navigation Bar not working properly

I am trying to make a navigation bar for the left side of my page but it is not working properly. 我正在尝试在页面左侧创建一个导航栏,但是它无法正常工作。 The link color won't change to green, the hover feature doesn't work, and the background color for the menu only covers the links themselves instead from top to bottom of the page. 链接颜色不会变为绿色,悬停功能不起作用,菜单的背景颜色仅覆盖链接本身,而不是页面顶部到底部。

 ul.nav { background-color: #f1f1f1; margin: 0px auto; width: 30%: height: 100%; position: fixed; overflow: hidden; } ul.nav li { display: block; height: 100%; width: 10%; { ul.nav li a { display: block; color: green; text-decoration: none; } ul.nav li a:hover { background-color: #555; color: white; } 
 <ul class="nav"> <li><a href="x">x</a></li> <li><a href="x">x</a></li> <li><a href="x">x</a></li> <li><a href="x">x</a></li> <li><a href="x">x</a></li> <li><a href="x">x</a></li> </ul> 

You have two typos in your CSS: 您的CSS中有两种错别字:

width: 30%:

You put a colon at the end, not a semicolon, so every property in that rule after width is being ignored. 您将冒号放在最后,而不是分号,因此该规则中宽度之后的每个属性都将被忽略。

...
width:10%;
        {
ul.nav li a {
...

You accidently put an opening bracket ( { ) here rather than a closing bracket ( } ). 您不小心在此处放置了一个右括号( { )而不是一个右括号( } )。 That's causing all your rules after that to be ignored. 这导致您之后的所有规则都被忽略。

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

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