Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
162
rated 0 times [  165] [ 3]  / answers: 1 / hits: 5501  / 10 Years ago, tue, march 11, 2014, 12:00:00

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 ?


More From » css

 Answers
3

Just set the height to 100% and the width to auto:



.foo {
background-size: auto 100%;
}

[#46948] Tuesday, March 11, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianom

Total Points: 601
Total Questions: 98
Total Answers: 109

Location: Kenya
Member since Fri, Dec 23, 2022
1 Year ago
lucianom questions
Tue, Feb 22, 22, 00:00, 2 Years ago
Wed, May 5, 21, 00:00, 3 Years ago
Sun, Jan 24, 21, 00:00, 3 Years ago
Sat, Aug 15, 20, 00:00, 4 Years ago
Mon, Jun 22, 20, 00:00, 4 Years ago
;