DaFunkyAlex
DaFunkyAlex

Reputation: 1969

Why does my CSS height transition not work?

I want the span tag to have a transition.

<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>

Check out this fiddle: https://jsfiddle.net/mnvbsLe0/

Upvotes: 0

Views: 1728

Answers (2)

Trang B. Nguyen
Trang B. Nguyen

Reputation: 36

When you do a transition, there is a before-transition state and after-transition state. Your before transition state has a height (.ausflug-themen > div > span) Your after-transition has a height of auto. You have to specify the exact height instead of auto because the browser doesn't how to transition from point A: height 20 px to point B: auto.

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;
  }

Upvotes: 1

Vinod Murukesan
Vinod Murukesan

Reputation: 231

I have made changes in your CSS file and it worked.

overwrite your css with the below mentioned 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;
  }

Upvotes: 2

Related Questions