postcss-retina-px-border
PostCSS plugin which create real physical pixel border dynamically on retina screen.
- if like this, could you please ⭐️star⭐ on github
History versions
Fast use
install
npm install postcss postcss-retina-px-border -D
or
yarn add postcss postcss-retina-px-border --dev
Init
- config in webpack(at root file postcss.config.js)
moduleexports = plugins:
- import the file (the file will be generated at 'src/retina-border.scss), you can also change the filename in options.
// app.js ;
Use and development
- the style generated have been transfer with autoprefixer, so just use it.
- then you can use the output selector directly, the selector with dpr 3 as follows, and you can also config by your self.
{ }
- use in other files:
notice: you should give a specific class selector of div such as '.text-box'. the example as follows:
box-content
Options
example
moduleexports = plugins: pxRange: 5
option list
option | type | default | description |
---|---|---|---|
baseDir | string | rootDir-of-project/src | a relative/absolute path to generate file, and this will be joined with filename param. such as 'src/' |
filename | string | 'retina-border.scss' | the name of target file to generate style with, such as retina-border.scss、 retina-border.less |
pxRange | number | 2 | the range of borderWidth to generate |
dprRange | number | 3 | the range of dpr to generate |
selector | string | '.retina-border-%dpx' | the format of selector when generating |
baseSelector | string | '.retina-border-box' | the base-style selector |
Strategy
- the new adaptation scheme of mobile h5 page based on viewport(vw/vh), so there is an problem that when we use small-px border, it become thicker than expected when rendered on retina screen.
- so we enlarge pseudo element size according to dpr, and then reduce the element with scale function.