David Laberge
David Laberge

Reputation: 16051

Using overflow and transformation together

I'm trying to add a flip card effect on a Div. The idea is to be able to see an image and flip it to fill a form. But the form is bigger then the image, so I would like to be able to scroll only the back of the "card"

source of the jsfiddle : http://24ways.org/2010/intro-to-css-3d-transforms/

I need to change the CSS to had the scroll when the form is display.

work in progress jsFiddle : http://jsfiddle.net/DavidLaberge2014/breb3f0e/

HTML :

<div class="row">
    <div class="container">
      <div id="card">
        <div class="front">
            <img src="http://lorempixel.com/250/300/sports/" />
        </div>
        <div class="back">
            <form>
                ...
            </form>
        </div>
      </div>
    </div>
</div>

CSS :

.container { 
    width:100%;
    height:100%;
}

#card {
  -webkit-transform-style: preserve-3d;
  -webkit-transition: -webkit-transform 1s;
  -webkit-transform-origin: right center;
}

#card div {
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
}

#card .front {

}

#card .back {
    -webkit-transform: rotateY(180deg);
    /*overflow:auto Add this and form gets hidden*/
}

#card.flipped {
  -webkit-transform: translateX(-100%) rotateY(-180deg);
}

Upvotes: 1

Views: 47

Answers (1)

Alessandro Incarnati
Alessandro Incarnati

Reputation: 7248

In order to add the scroll to the translated div containing your form, you should:

Give a fixed height to the card

#card div {
  display: block;
  position: absolute;
  width: 100%;
  height: 300px;
  -webkit-backface-visibility: hidden;
}

Add the overflow to the #card .back container.

   #card .back {
       overflow-y:scroll;          
       width: 100%;
       height: 300px;           
       position:absolute;  
    }

Then position the button any way you prefer on the page either absolute, fixed or relative positioned, outside the card area.

DEMO http://jsfiddle.net/a_incarnati/ysxeu9w8/1/

Upvotes: 2

Related Questions