Giter Site home page Giter Site logo

bitstarr / superscale.css Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 2 KB

A CSS snippet to ensure your website gets scaled proportionally on large resolution screens above a certain screen resolution

License: MIT License

CSS 100.00%
4k css high-resolution retina scaling

superscale.css's Introduction

superscale.css

What happens to the website when the screen is really big and really high resolution? Your design team shrugs its shoulders and the client complains about the narrow content strip in the whitespace prairie?

Save yourself the discussion, just blow the thing up above FullHD - with superscale.css!

How it works

:root {
    /* super scale! */
    @media ( min-width: 120.01rem ) {
        font-size: calc( 100vw / 120 );
    }
    /* but not for iOS - it's not smart enough */
    @supports (-webkit-touch-callout: none) {
        font-size: 1rem;
    }
}

Provided the base font-size of your website is equal to 16px, a FullHD viewport will be 120rem wide and you are using only relative and font based units. To keep scaling proportioanlly, the :root font-size will be set to a calculation of a 120th of 100vw after the breakpoint of 120rem. After that point we lock the 1rem unit to this fraction of the viewport size.

Demo

Look at this CodePen example.

Customization

If you want to fix your design earlier or later, you need to modify calculation. For example you want to start scaling at 2240px viewport width (at 1rem=16px), replace 120 with 140. The math is 1920/16 = 120 and 2240/16 = 140.

Caveats

This method requires you to use relative units, preferredly font units (rem, em, ex, ch, โ€ฆ) and percentages for basically everything! Every use of pixel units could cause problems.

Also certain browsers (looking at this californian orchard) or the way you work with font-size on the html element may cause issues.

I am using this for some years in multiple projects and only ran in a few issues that could be fixed. While testing there were hardly issues when setting a different body font size than (equal to) 16px. The media query in :root seems to be oriented to the browser setting. If the user sets its default font size to 20px, your scaling may begin earlier than you expect, but assuming the user set this fonts size deliberately, it will encourage accessibilty though.

superscale.css's People

Contributors

bitstarr avatar

Stargazers

Steven Foncken avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.