Y
Y
yadomot2015-09-16 13:12:30
css
yadomot, 2015-09-16 13:12:30

How to animate width and height of div position:absolute?

There is a block, position: absolute
on hover, the width increases,
but if the block has top and left properties, then on hover it increases but also shifts to the right and down.
How to enlarge a block without shifting its center?
Also, what is the right way to specify in css the transition-property width and height so that they increase synchronously,
as with transition-property: all ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Ineshin, 2015-09-16
@yadomot

transform: scale(N);
UPD works best for this task :
Change Center can be controlled using transform-origin

D
Dmitry Novikov, 2015-09-16
@dmitriy_novikov

Here are the styles for an example, make the necessary changes and use it.

div{top:100px; left:100px; position:absolute; width:100px; height:100px; background:green; transition:0.5s ease all;}
div:hover{width:200px; height:200px; top:50px; left:50px; }

R
Rithmsamba, 2015-09-16
@Rithmsamba

Use transform-origin
You can read it here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question