简体   繁体   English

如何在悬停时水平而不是垂直拉伸图像?

[英]How to stretch my image horizontally but not vertically on hover?

 .film{ text-align: center; width: 234px; min-height: 311px; position: relative; z-index: 1; overflow: hidden; } .poster{ width: 234px; height: 311px; -moz-transition: all 1s ease-out; -o-transition: all 1s ease-out; -webkit-transition: all 1s ease-out; display: block; } .poster:hover{ -webkit-transform: scale(1.1); -moz-transform: scale(1.1); -o-transform: scale(1.1); transform: scale(1.1); } .film_name{ font-size: 24px; word-wrap: break-word; font-family: 'Roboto', 'Arial', 'Tahoma', sans-serif; font-weight: 700; } .year{ color: #00dfff; } 
 <div class="film"> <a href="#" target="_blank"> <img class="poster" src="https://st.kp.yandex.net/images/poster/sm_3362295.jpg" alt="Годзилла 2: Король монстров"> <div class="triangle"> <span class="triangle__line"></span> <span class="triangle__line"></span> <span class="triangle__line"></span> </div> <div class="film_name">Годзилла 2: Король монстров</div> <div class="year">2019</div> </div> </a> </div> 

How to make the picture go beyond the vertical? 如何使图片超出垂直方向?

The height ( .film{ min-height: 311px;} ) property does not need to be changed. 高度( .film{ min-height: 311px;} )属性无需更改。

Change overflow: hidden; 更改overflow: hidden; to overflow: visible; overflow: visible; in the film class. 在电影课上。 See below: 见下文:

.film {
    text-align: center;
    width: 234px;
    min-height: 311px;
    position: relative;
    z-index: 1;
    overflow: visible;
}

add div (poster-panel) to image tag and set overflow:hidden... so the image will stretch inside the poster-panel div. 将div(海报面板)添加到图片标签并设置overflow:hidden ...,以便图片将在海报面板div中拉伸。

 .film{ text-align: center; width: 234px; min-height: 311px; position: relative; z-index: 1; overflow: hidden; } .poster-panel{ overflow: hidden; } .poster{ width: 234px; height: 311px; -moz-transition: all 1s ease-out; -o-transition: all 1s ease-out; -webkit-transition: all 1s ease-out; display: block; } .poster:hover{ -webkit-transform: scale(1.1); -moz-transform: scale(1.1); -o-transform: scale(1.1); transform: scale(1.1); } .film_name{ font-size: 24px; word-wrap: break-word; font-family: 'Roboto', 'Arial', 'Tahoma', sans-serif; font-weight: 700; } .year{ color: #00dfff; } 
 <div class="film"> <a href="#" target="_blank"> <div class="poster-panel"> <img class="poster" src="https://st.kp.yandex.net/images/poster/sm_3362295.jpg" alt="Годзилла 2: Король монстров"> </div> <div class="triangle"> <span class="triangle__line"></span> <span class="triangle__line"></span> <span class="triangle__line"></span> </div> <div class="film_name">Годзилла 2: Король монстров</div> <div class="year">2019</div> </div> </a> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM