DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Firefox’s “funny” CSS3 Image Scaling Quirk

Firefox’s “funny” CSS3 Image Scaling Quirk

Swizec Teller user avatar by
Swizec Teller
·
Oct. 20, 11 · Web Dev Zone · Interview
Like (0)
Save
Tweet
7.41K Views

Join the DZone community and get the full member experience.

Join For Free

last night as i was rewriting the css for postme.me from scratch and i was cursing and shouting obscenities under my breath and trying to find a way to punch all of mozilla in the face over the internet … i discovered something silly.


a quirk

scaling images is something every developer on the web has had to come to grips with. maybe you were implementing an image gallery and wanted to display thumbnails, maybe you’ve reimplemented all the scaling algorithms several times.

it’s surprising how complex something as simple as making sure no dimension is beyond a certain size while maintaining aspect ratio can be. which is exactly why i wanted to avoid the whole thing this time ’round and let the browser take care of it all.

should be pretty simple with css right?

turns out it is, here’s everything you have to do:

img {
   max-width: 300px;
   max-height: 200px;
}

casting aside concerns such as load times and bandwidth for a moment. this is an elegant solution to a hairy problem. browsers as it turns out do exactly the right thing – make sure neither dimension is too big and carefully adjusting the other dimension to maintain aspect ratio.

but try putting that image into a flexbox div and strange things start happening in firefox.

flexbox and image scaling in ff

what’s stranger still is that wrapping that same image into a vanilla div with zero styling not only fixes the image resizing issue, but also maintains centering and other flexbox properties you were originally going for.

and then it works

you can check it out in action here .

not sure exactly what’s going on here, but  i’m glad i managed to find a fix for one strange thing among many. now i have a website full of very very nonsemantic html simply  because of javascript’s quirks.

this brings up memories of times before i decided i don’t care about ie support anymore … granted, these features are far from standardized and it’s therefore to be expected strangeness might appear. but firefox is not where i expected such problems to crop up.

source: http://swizec.com/blog/firefoxs-funny-css3-image-scaling-quirk/swizec/2641

CSS Scaling (geometry)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • ETL, ELT, and Reverse ETL
  • Real-Time Supply Chain With Apache Kafka in the Food and Retail Industry
  • This Is How You Give Good Feedback at Work
  • A First Look at CSS When and Else Statements

Comments

Web Dev Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo