CSS: How to scale an image from the center instead of top-left

前端 未结 4 1217
你的背包
你的背包 2020-12-06 00:43

So my problem is that I have an image and I set its CSS to have a

max-width: 100% 

which scales it at lower resolutions ( as will be seen

4条回答
  •  爱一瞬间的悲伤
    2020-12-06 00:47

    Just replace width: 400px; with transform: scale(2,2) on :hover.

    img {
        width: 100%; max-width: 100%;
    }
    div {
        position: absolute; left: 20%; top: 20%;
        width: 250px;
        transition: all 2s ease-in-out;
    }
    div:hover {
        transform: scale(2,2)
    }

提交回复
热议问题