admin管理员组文章数量:1237560
Is there a way of making a background fit a div "height" while keeping his ratio ? Like a contain but for "y" only ? according to this answer there isn't Background Image Scaling While Maintaining Aspect Ratio however considering that the most voted answer quoted some css3 possiblities I was wondering if there was a way nowdays to do so in css3 or maybe javascript ?
Is there a way of making a background fit a div "height" while keeping his ratio ? Like a contain but for "y" only ? according to this answer there isn't Background Image Scaling While Maintaining Aspect Ratio however considering that the most voted answer quoted some css3 possiblities I was wondering if there was a way nowdays to do so in css3 or maybe javascript ?
Share Improve this question edited May 23, 2017 at 10:29 CommunityBot 11 silver badge asked Mar 11, 2014 at 19:39 Brennan SeiBrennan Sei 1,0431 gold badge9 silver badges12 bronze badges2 Answers
Reset to default 17Just set the height to 100%
and the width to auto
:
.foo {
background-size: auto 100%;
}
I think this will do it:
.myDiv { background-size: cover; }
See the details here: http://www.w3schools./cssref/css3_pr_background-size.asp
本文标签: javascriptBackgroundsizecontain quotyquotStack Overflow
版权声明:本文标题:javascript - Background-size:contain "y"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739902482a2207285.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论