最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Background-size:contain "y"? - Stack Overflow

programmeradmin5浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 17

Just 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

发布评论

评论列表(0)

  1. 暂无评论