Skip to content

Commit 459fdfe

Browse files
authored
Update README.md
Added instructions for use
1 parent 0a29221 commit 459fdfe

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,66 @@
1-
# postcss-responsive-value
1+
# PostCSS Responsive Values
2+
3+
This PostCSS plugin provides you with the `res-val()` function, which allows you to use dynamic values instead of static CSS values that are automatically reduced from a certain breakpoint.
4+
5+
The function receives three values: Min, Max and a breakpoint. As long as the page width is greater than or equal to the breakpoint, it outputs the max value. As soon as the page width falls below the breakpoint, the value is scaled proportionally to the width until the Min value is reached.
6+
7+
> The function currently only works with pixel values.
8+
9+
## Example & Usage
10+
In the `res-val()` function, the **first** value is always the `minimum value (Min)`, the **second** value is the `maximum value (Max)`. The **third** value is the `breakpoint`, which will be discussed below.<br><br>
11+
**In your CSS input file:**
12+
```css
13+
.heading {
14+
font-size: res-val(32, 60, 1200);
15+
}
16+
```
17+
**The CSS output:**
18+
```css
19+
.heading {
20+
font-size: clamp(32px, 100vw * (60 / 1200), 60px);
21+
}
22+
```
23+
This causes the `.heading` class to have a font size of `60px`. As soon as the page width is smaller than `1200px`, the font size is reduced in relation to the page width until a size of `32px` is reached.
24+
25+
The function can of course be used on all CSS specifications that can work with pixel values. Width, Height, Margin, Pudding etc. All values that are needed to smoothly scale a layout smaller without media queries.
26+
27+
## Installation
28+
To use the plugin, it can either be installed via npm or the `index.js` must be inserted into the development environment.
29+
If the script is inserted manually, the `index.js` script must be renamed to `postcss-responsive-value.js`.
30+
31+
### PostCSS registration
32+
In order for the plugin to be used in the PostCSS build process, it must be registered in the PostCSS config file.
33+
```js
34+
export default {
35+
plugins: {
36+
"postcss-responsive-value": {},
37+
}
38+
}
39+
```
40+
## Breakpoints
41+
The `default breakpoint` for the script is `769px`. This default breakpoint is always used if no separate breakpoint is specified in the respective `res-val()` function.
42+
If a breakpoint is specified in a `res-val()` function, it is only used for this function.
43+
44+
### Function without its own breakpoint
45+
This function will use the default breakpoint
46+
```css
47+
.wrapper {
48+
width: res-val(1000, 1600);
49+
}
50+
```
51+
### Function with its own breakpoint
52+
```css
53+
.wrapper {
54+
width: res-val(1000, 1600, 1300);
55+
}
56+
```
57+
### Overwrite default breakpoint
58+
You can also define the default breakpoint yourself. This must be specified in the PostCSS config as follows:
59+
```js
60+
export default {
61+
plugins: {
62+
'postcss-responsive-value': { breakpoint: '1920' },
63+
}
64+
}
65+
```
66+
In this example, the breakpoint would be set to 1920px.

0 commit comments

Comments
 (0)