简体   繁体   English

CSS的新功能-过渡无效

[英]New to CSS - Transitions not working

I am throwing together a really quick, really informal website for a school science project. 我正在为一个学校科学项目创建一个非常快速,非常非正式的网站。 However, the transitions on my list items aren't working when I hover over them. 但是,将鼠标悬停在列表项上时,它们上的过渡不起作用。 I'd like to apologize in advance for the messy HTML/CSS. 我想对乱七八糟的HTML / CSS表示歉意。

 body { background-color: black; } header { background-color: #4C99FF; height: 10%; float: right; border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; } .nav-button { height: 90%; border: 1px solid white; border-radius: 5px; text-align: center; } #button-one { float: left; } #button-two { float: right; } .button-text { color: white; font-size: 2vw; border: 1px solid white; } .nav-list { list-style-type: none; } .nav-item { display: inline-block; color: white; margin-top: 3%; font-size: 2vw; border: 1px solid white; border-radius: 5px padding: 25px; -webkit-transition: color .5s; -webkit-transition: background-color: .5s; -moz-transition: color .5s; -moz-transition: background-color: .5s; } .nav-item:hover { color: #4C99FF; background-color: white; } #home { float: left; } #cited { float: right; margin-right: 15%; } 
 <div class="container-fluid"> <div class="row"> <div class="col-xs-10 col-sm-8 col-md-6 col-lg-4 header"> <!--<div class="col-xs-3 nav-button" id="button-one"> <a href="#"><h1 class="button-text"> Home<span></span> </h1></a> </div> <div class="col-xs-3 nav-button" id="button-two"> <h1 class="button-text"> Cited </h1> --> <ul class="nav-list"> <a href="#"> <li class="nav-item" id="home">Home</li> </a> <a href="#"> <li class="nav-item" id="cited">Cited</li> </a> </ul> </div> </div> </div> 

Could someone help me with this problem? 有人可以帮我解决这个问题吗? Once again, I am very sorry for the messy code. 再次,我为代码混乱感到非常抱歉。

Theres a couple of things, first you should not use semi-colons for the style attributes, it should be like this instead: 有两件事,首先您不应该对样式属性使用分号,而是应该像这样:

-webkit-transition: background-color .5s;

You also shouldn't define transitions separately, it should be comma separated like this: 您也不应该单独定义转换,它应该用逗号分隔,如下所示:

-webkit-transition: color .5s, background-color .5s;

And finally, you should be using the transition style attribute aswell, not just the webkit and moz ones. 最后,您还应该使用transition样式属性,而不仅仅是webkit和moz。

transition: color .5s;

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

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