GithubHelp home page GithubHelp logo

postcss-aspect-ratio-polyfill's People

Contributors

takamoso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postcss-aspect-ratio-polyfill's Issues

it don't work with height based element

This polyfill only work with width based elements

example:

<div class="width-based aspect-ratio-box"></div>
<div class="height-based aspect-ratio-box"></div>
.width-based {
  display: inline-block;
  border: 1px solid blue;
  width: 80px;
}

.height-based {
  display: inline-block;
  border: 1px solid red;
  height: 80px;
}

.aspect-ratio-box::before {
  float: left;
  padding-top: 56.25%;
  content: '';
}
.aspect-ratio-box::after {
  display: block;
  content: '';
  clear: both;
}

the 2nd element have a 0px width

Polyfill has problems with multiple selector rules

This gets polyfilled correctly:

.image-container-1 {
  aspect-ratio: 1 / 1
}
.image-container-2 {
  aspect-ratio: 1 / 1;
}

This does not:

.image-container-1, .image-container-2 {
  aspect-ratio: 1 / 1;
}

[enhancement] Wrap polyfill in `@supports not`

This polyfill unnecessarily removes and replaces aspect-ratio even in browsers where it is supported.

I suggest that the original aspect-ratio property is left intact, and the polyfill-generated code is wrapped in a @supports not instruction.

https://developer.mozilla.org/en-US/docs/Web/CSS/@supports

Input:

.aspect-ratio-box {
  aspect-ratio: 16 / 9;
}

Expected output:

.card-wide {
    aspect-ratio: 16 / 9;
}

@supports not (aspect-ratio: 1/1) {
  .aspect-ratio-box::before {
    float: left;
    padding-top: 56.25%;
    content: '';
  }
  .aspect-ratio-box::after {
    display: block;
    content: '';
    clear: both;
  }
}

Note: 1/1 is used only as a test value to check whether aspect-ratio is supported at all, it does not affect the resulting layout.

[bug] Fails when using `calc()` and variables

When using the CSS calc() function and variables to calculate aspect-ratio in my source CSS, the rule fails to compile properly

Input source:

.card-cell {
            --card-width: 1;
            --card-height: 1;
            aspect-ratio: calc(var(--card-width) / var(--card-height));
}

Output:

.card-cell::before {
    float: left;
    padding-top: calc(var(--card-width)NaN%var(--card-height));
    content: '';
}

Seems that this library doesn't work well when passing a single value to aspect-ratio which should be possible according to the docs:

If height and the preceding slash character are omitted, height defaults to 1

Since padding-top requires a percentage value, this can be fixed easily by multiplying the value by 100% inside of another calc(), which results in working code.

Expected output:

.card-cell::before {
    float: left;
    padding-top: calc( calc(var(--card-width) / var(--card-height) ) * 100%);
    content: '';
}

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.