1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
# Oldie [![Build Status][ci-img]][ci]
<img align="right" width="135" height="95" src="http://postcss.github.io/postcss/logo-leftp.png" title="Philosopher’s stone, logo of PostCSS">
[Oldie] tranforms CSS to be compatible with old Internet Explorer.
```html
<!--[if gt IE 8]><!--><link href="style.css" rel="stylesheet"><!--<![endif]-->
<!--[if lte IE 8]><link href="style.oldie.css" rel="stylesheet"><![endif]-->
```
If you’re like me, you stopped supporting IE8 years ago. Yet, here you are, satisfying another client that somehow managed to get this requirement past you.
### Flatten Media Queries
Resolve media queries for a desktop experience.
```css
/* before */
body {
font-size: 12px;
}
@media screen and (max-width: 767px) {
body {
font-size: 16px;
}
}
@media screen and (min-width: 768px) {
body {
color: #444;
}
}
/* after */
body {
font-size: 12px;
}
body {
color: #444;
}
```
### Replace :root
Swap `:root` selectors with `html` selectors.
```css
/* before */
:root {
background-color: black;
color: white;
}
/* after */
html {
background-color: black;
color: white;
}
```
### Reduce calc()
Reduce `calc()` references whenever possible.
```css
/* before */
.banner {
font-size: calc(16px * 3);
}
/* after */
.banner {
font-size: 48px;
}
```
### Resolve rem
Resolve `rem` values as standard pixels.
```css
/* before */
.container {
margin-top: 2.5rem;
}
/* after */
.container {
margin-top: 40px;
}
```
### Uphold opacity
Swap `opacity` properties with IE8 compatible `filter` properties.
```css
/* before */
.figure {
opacity: .5;
}
/* after */
.figure {
filter: alpha(opacity=50);
}
```
### Patch pseudo-elements
Swap `::` selectors with IE8 compatible `:` selectors.
```css
/* before */
a::after {
content: " (" attr(href) ")";
}
/* after */
a:after {
content: " (" attr(href) ")";
}
```
### Retain rgba colors
Swap `rgba` values with IE8 compatible hex values and filter properties.
```css
/* before */
.hero {
background-color: rgba(153, 221, 153, .8);
border: solid 1px rgba(100, 102, 103, .3);
}
/* after */
.hero {
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#8099dd99',endColorstr='#8099dd99');
border: solid 1px #646667;
}
```
### Forget :not
Remove `:not()` selectors while preserving the other selectors in a rule.
```css
/* before */
.a, .b:not(.c), d {
color: red;
}
/* after */
.a, .d {
color: red;
}
```
### Salvage :nth-child
Swap `:nth-child` selectors with `:first-child`.
```css
/* before */
.container > p:nth-child(4).specific > span {
font-weight: bold;
}
/* after */
.container > :first-child + * + * + p.specific > span {
font-weight: bold;
}
```
## Plugins
[Oldie] is powered by the following plugins:
- [PostCSS Calc](https://github.com/postcss/postcss-calc)
- [PostCSS UnMQ](https://github.com/jonathantneal/postcss-unmq)
- [PostCSS UnRoot](https://github.com/jonathantneal/postcss-unroot)
- [PostCSS UnNth](https://github.com/jonathantneal/postcss-unnth)
- [PostCSS UnNot](https://github.com/jonathantneal/postcss-unnot)
- [PostCSS UnOpacity](https://github.com/jonathantneal/postcss-unopacity)
- [PostCSS UnRGBA](https://github.com/jonathantneal/postcss-unrgba)
- [PostCSS Pixrem](https://github.com/robwierzbowski/node-pixrem)
- [PostCSS Pseudo Elements](https://github.com/axa-ch/postcss-pseudoelements)
Some of these plugins have more features than are described here. Visit their project pages to learn more about them individually.
## Usage
Follow these steps to use [Oldie].
Add [Oldie] to your build tool:
```bash
npm install oldie --save-dev
```
#### Node
```js
require('oldie')({ /* options */ }).process(YOUR_CSS);
```
#### PostCSS
Add [PostCSS] to your build tool:
```bash
npm install postcss --save-dev
```
Load [Oldie] as a PostCSS plugin:
```js
postcss([
require('oldie')({ /* options */ })
]);
```
#### Gulp
Add [Gulp PostCSS] to your build tool:
```bash
npm install gulp-postcss --save-dev
```
Enable [Oldie] within your Gulpfile:
```js
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./css/src/*.css').pipe(
postcss([
require('oldie')({ /* options */ })
])
).pipe(
gulp.dest('./css')
);
});
```
#### Grunt
Add [Grunt PostCSS] to your build tool:
```bash
npm install grunt-postcss --save-dev
```
Enable [Oldie] within your Gruntfile:
```js
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('oldie')({ /* options */ })
]
},
dist: {
src: 'css/*.css'
}
}
});
```
## Options
Each plugin’s options may be configured by targeting the plugin’s namespace. Any plugins may be disabled by giving them a `disable` property.
Example:
```js
require('oldie')({
rgba: {
filter: true
},
rem: {
replace: false
},
unmq: {
disable: true
}
})
```
[ci]: https://travis-ci.org/jonathantneal/oldie
[ci-img]: https://travis-ci.org/jonathantneal/oldie.svg
[Gulp PostCSS]: https://github.com/postcss/gulp-postcss
[Grunt PostCSS]: https://github.com/nDmitry/grunt-postcss
[PostCSS]: https://github.com/postcss/postcss
[Oldie]: https://github.com/jonathantneal/oldie
|