這裏是一個的jsfiddle鏈接:http://jsfiddle.net/qrzwD/如何制止這種刺激性的CSS行爲
我只是不喜歡我的第二個立在動畫完成後向上移動。
有人可以幫我阻止這件事。
這裏是我的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));});
});
有效。但可以解釋發生了什麼問題 – shubendrak
您正在A元素內添加一個新的span元素,使整體高度發生變化。第一個A元素推動第二個下跌 – Mircea
感謝噸。我知道了。 – shubendrak