我有一个盒子,有两个单独的css转换同时发生。
当转换发生时,图标下方的标题和段落文本移动位置
见JS小提琴:http://jsfiddle.net/Lsnbpt8r/
继承我的HTML
<div class="row">
<div class="col-md-4 text-center transistion">
<div class="box">
<i class="circle-pos circle glyphicon glyphicon-home icon"></i>
<h3 class="heading">
Construction
</h3>
<p>This is how we do it</p>
</div>
</div>
<div class="col-md-4 text-center transistion">
<div class="box">
<i class="circle-pos circle glyphicon glyphicon-wrench icon"></i>
<h3 class="heading">
Interior Design
</h3>
<p>This is how we do it</p>
</div>
</div>
<div class="col-md-4 text-center transistion">
<div class="box">
<i class="circle-pos circle glyphicon glyphicon-thumbs-up icon"></i>
<h3 class="heading">
Service
</h3>
<p>This is how we do it</p>
</div>
</div>
</div>
继承人我的css
.icon {
font-size: 32px;
vertical-align: middle;
padding-top: 35px;
padding-right: 9px;
}
.icon:hover{
font-size: 48px;
color: #003176;
padding-top: 25px;
padding-right: 5px;
}
.circle {
width: 120px;
height: 120px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #f3f3f3;
-webkit-transition: all 300ms linear;
-moz-transition: all 300ms linear;
-o-transition: all 300ms linear;
-ms-transition: all 300ms linear;
transition: all 300ms linear;
}
.box:hover .circle{
width: 100px;
height: 100px;
background: #f7f7f7;
}
.circle-pos{
margin-top: -60px;
}
.box:hover .circle-pos{
margin-top: -50px;
}
.box:hover .icon{
font-size: 48px;
color: #003176;
padding-top: 25px;
padding-right: 5px;
}
.box{
border: 0px 1px 2px 1px solid #f1f1f1;
border-top: 5px solid #003176;
height: 150px;
font-size: 18px;
-webkit-transition: all 300ms linear;
-moz-transition: all 300ms linear;
-o-transition: all 300ms linear;
-ms-transition: all 300ms linear;
transition: all 300ms linear;
}
.box:hover{
background-color: #135379;
color: #b9f9ff;
}
.heading{
padding: 50px 0 12px 0;
margin: 0 0 25px 0;
height: 24px;
position: relative;
text-transform: uppercase;
letter-spacing: -0.03em;
}
.transistion{
padding-top: 60px;
}
我已经为盒子设置了一个固定的高度,但这并不能阻止文本移动,任何帮助或建议都会受到赞赏。
答案 0 :(得分:3)
将您的图标包装在容器中:
<div class="icon-container">
<i class="circle-pos circle glyphicon glyphicon-home icon"></i>
</div>
并给它一个固定的高度:
.icon-container {
height: 50px; // Or whatever you want
}
为我顺利工作(我只将它应用到第一个图标):http://jsfiddle.net/63Lbwonf/2/ 你可以玩数字。我只是在那里扔了50px并修复了容器高度,因此在动画过程中H1不会移动。
答案 1 :(得分:2)
为h3
和下面的文字添加额外的div,在这种情况下,我将其命名为.bottombox
。然后我给它一个position:absolute
属性,这样我就可以把它从剩余元素的流中取出来,这意味着它不会受到动画大小,填充和边距变化的影响。
因此,您的HTML是这样的:
<div class="row">
<div class="col-md-4 text-center transistion">
<div class="box"> <i class="circle-pos circle glyphicon glyphicon-home icon"></i>
<div class="bottombox">
<h3 class="heading">
Construction
</h3>
<p>This is how we do it</p>
</div>
</div>
</div>
<div class="col-md-4 text-center transistion">
<div class="box"> <i class="circle-pos circle glyphicon glyphicon-wrench icon"></i>
<div class="bottombox">
<h3 class="heading">
Interior Design
</h3>
<p>This is how we do it</p>
</div>
</div>
</div>
<div class="col-md-4 text-center transistion">
<div class="box"> <i class="circle-pos circle glyphicon glyphicon-thumbs-up icon"></i>
<div class="bottombox">
<h3 class="heading">
Service
</h3>
<p>This is how we do it</p>
</div>
</div>
</div>
</div>
然后这是你的CSS:
.icon {
font-size: 32px;
vertical-align: middle;
padding-top: 35px;
padding-right: 9px;
}
.icon:hover {
font-size: 48px;
color: #003176;
padding-top: 25px;
padding-right: 5px;
}
.circle {
width: 120px;
height: 120px;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
background: #f3f3f3;
-webkit-transition: all 300ms linear;
-moz-transition: all 300ms linear;
-o-transition: all 300ms linear;
-ms-transition: all 300ms linear;
transition: all 300ms linear;
}
.circle:hover {
width: 100px;
height: 100px;
background: #f7f7f7;
}
.circle-pos {
margin-top: -60px;
}
.circle-pos:hover {
margin-top: -50px;
}
.box {
border: 0px 1px 2px 1px solid #f1f1f1;
border-top: 5px solid #003176;
height: 200px;
-webkit-transition: all 300ms linear;
-moz-transition: all 300ms linear;
-o-transition: all 300ms linear;
-ms-transition: all 300ms linear;
transition: all 300ms linear;
position:relative;
}
.box:hover {
background-color: #135379;
}
.heading {
padding: 60px 0 12px 0;
margin: 0 0 13px 0;
height: 24px;
text-transform: uppercase;
letter-spacing: -0.03em;
}
.bottombox {
bottom:20px;
left:0;
width:100%;
text-align:center;
position: absolute;
}
.transistion {
padding-top: 60px;
}
当然,如果需要,你可以做一些改变,但这或多或少是它的要点
答案 2 :(得分:0)
问题是您的文字相对于圆圈定位,并且圆圈在过渡中变小。您可以向margin-bottom: 10px;
添加类似.circle:hover{}
的内容,但这会使文本在转换期间出现抖动,因此我建议将文本置于绝对位置。