編碼的世界 / 優質文選 / 生涯

css實現在鼠標放上去時圖片從中心位置變大


2022年3月20日
-   

源自:https://stackoverflow.com/questions/28726430/css-how-to-scale-an-image-from-the-center-instead-of-top-left
實現:鼠標放到圖片上時,圖片從中心位置變大,而不是從左上角為原點變大。
img {
width: 100%; max-width: 100%;
}
div {
position: absolute; left: 20%; top: 20%;
width: 250px;
transition: all 2s ease-in-out;//這裏表示動畫的時間為2s
}
div:hover {//hover表示鼠標移動到上面時,觸發這個事件
transform: scale(2,2);//transform表示變換,scale表示範圍、大小,這是長寬都變為2倍的實現代碼。
}

另一部分代碼:
<div>
<a href="http://photobucket.com/images/cat" target="_blank">
<img src="http://i583.photobucket.com/albums/ss278/campipr/coolcat.gif"/>
</a>
</div>

熱門文章