如何阻止这种恼人的CSS行为

时间:2013-05-15 11:01:29

标签: jquery html css css-float html-lists

这是一个jsfiddle链接:http://jsfiddle.net/qrzwD/

我不喜欢我的第二个li在动画完成后向上移动。

有人可以帮助我阻止这一点。

这是我的HTML:

 <nav>
    <ul>
        <li> <a class="content-box-blue" href="#"> </a> </li>
        <li> <a class="content-box-gray" href="#"> </a> </li>
    </ul>
</nav>

这是我的css:

* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
a {
text-decoration: none;
margin: 0;
padding: 0;
}
ul, li, nav {
margin: 0;
padding: 0;
}
nav {
float: right;
width: 400px;
margin-top: 35px;
margin-right: 10px;
}
nav ul {
list-style-type: none;
float: right;
}
nav li {
float: right;
clear: right;
margin-bottom: 20px;
}
.content-box-blue {
background-color: #00bfff;
border: 1px solid #afcde3;
height: 50px;
width: 0px;
border-top-left-radius: 8% 50%;
border-bottom-left-radius: 8% 50%;
text-align:center;
line-height:50px;
 }
 .content-box-gray {
background-color: #FF69B4;
border: 1px solid #bdbdbd;
height: 50px;
width: 0px;
border-top-left-radius: 12% 50%;
border-bottom-left-radius: 12% 50%;
text-align:center;
line-height:50px;
 }

这是我的jquery代码:

$(function(){
    $(".content-box-blue").animate({width:'350px'},1200,function(){$('<span>Charcoal Paintings</span>').fadeIn(1000).appendTo($(this));});

    $(".content-box-gray").animate({width:'250px'},1200,function(){$('<span>Sketches</span>').fadeIn(2000).appendTo($(this));});

});

4 个答案:

答案 0 :(得分:5)

在LI上设置高度而不是A:

li {height:50px;}

http://jsfiddle.net/qrzwD/3/

新添加的A使LI改变整体高度

答案 1 :(得分:3)

可以通过为.content-box-blue和.content-box-grey

设置display:block来解决此问题。

fiddle here

答案 2 :(得分:1)

除了a-selector之外,您还可以通过将li元素的静态height: 50px添加到常规nav li - 选择器来解决此问题。

但是,我不能解释为什么它会这样做。

答案 3 :(得分:1)

请尝试

nav li a{
    display:block;
}

在这里链接http://jsfiddle.net/qrzwD/4/