为什么我的 CSS 高度转换不起作用?
Why does my CSS height transition not work?
我希望 span 标签有一个过渡。
<div id="lorem1"><img src="http://www.lorempixum.com/100/100/" />
<span><!-- this one here should smoothly grow... -->
<strong>LOREM!</strong><br />
<span class="infotext">Lorem ipsum</span>
</span>
</div>
看看这个 fiddle:https://jsfiddle.net/mnvbsLe0/
我已经对您的 CSS 文件进行了更改并且它起作用了。
用下面提到的 CSS
覆盖你的 css
.ausflug-themen {
display: flex;
flex-wrap: wrap;
overflow:hidden;
}
.ausflug-themen > div {
position: relative;
margin: 5px;
}
.ausflug-themen > div > span {
position: absolute;
left: 0;
bottom: 0px;
border: 100px;
background-color: rgba(0,0,0,.5);
width: 80px;
color: #fff;
padding: 10px;
font-size: 1.3em;
height: 20px;
-webkit-transition: all 0.4s ease-out;
-moz-transition: all 0.4s ease-out;
-o-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
}
span.infotext {
height:0;
color: #fff;
}
.ausflug-themen > div:hover > span {
height: 80px;
}
当你进行转换时,有转换前状态和转换后状态。你之前的过渡状态有一个高度 (.ausflug-themen > div > span) 你的转换后有一个高度自动。您必须指定确切的高度而不是自动,因为浏览器不知道如何从 A 点:高度 20 像素过渡到 B 点:自动。
Before-transition:
.ausflug-themen > div > span {
position: absolute;
left: 0;
bottom: 0px;
border: 100px;
background-color: rgba(0,0,0,.5);
width: 80px;
color: #fff;
padding: 10px;
font-size: 1.3em;
height: 20px;
transition: height 2.0s;
}
After-transition:
.ausflug-themen > div:hover > span {
cursor: default;
height: auto;
}
我希望 span 标签有一个过渡。
<div id="lorem1"><img src="http://www.lorempixum.com/100/100/" />
<span><!-- this one here should smoothly grow... -->
<strong>LOREM!</strong><br />
<span class="infotext">Lorem ipsum</span>
</span>
</div>
看看这个 fiddle:https://jsfiddle.net/mnvbsLe0/
我已经对您的 CSS 文件进行了更改并且它起作用了。
用下面提到的 CSS
覆盖你的 css.ausflug-themen {
display: flex;
flex-wrap: wrap;
overflow:hidden;
}
.ausflug-themen > div {
position: relative;
margin: 5px;
}
.ausflug-themen > div > span {
position: absolute;
left: 0;
bottom: 0px;
border: 100px;
background-color: rgba(0,0,0,.5);
width: 80px;
color: #fff;
padding: 10px;
font-size: 1.3em;
height: 20px;
-webkit-transition: all 0.4s ease-out;
-moz-transition: all 0.4s ease-out;
-o-transition: all 0.4s ease-out;
transition: all 0.4s ease-out;
}
span.infotext {
height:0;
color: #fff;
}
.ausflug-themen > div:hover > span {
height: 80px;
}
当你进行转换时,有转换前状态和转换后状态。你之前的过渡状态有一个高度 (.ausflug-themen > div > span) 你的转换后有一个高度自动。您必须指定确切的高度而不是自动,因为浏览器不知道如何从 A 点:高度 20 像素过渡到 B 点:自动。
Before-transition:
.ausflug-themen > div > span {
position: absolute;
left: 0;
bottom: 0px;
border: 100px;
background-color: rgba(0,0,0,.5);
width: 80px;
color: #fff;
padding: 10px;
font-size: 1.3em;
height: 20px;
transition: height 2.0s;
}
After-transition:
.ausflug-themen > div:hover > span {
cursor: default;
height: auto;
}