Skip to content

Commit 2c2eff4

Browse files
committed
Change integer pixels value only on integer pixel
1 parent 6c817ea commit 2c2eff4

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ module.exports = postcss.plugin('postcss-media-minmax', function () {
3232

3333
function create_query(name, gtlt, eq, value, params) {
3434
return value.replace(/([-\d\.]+)(.*)/, function (match, number, unit) {
35+
var initialNumber = parseFloat(number);
3536

3637
if (parseFloat(number) || eq) {
3738
// if eq is true, then number remains same
3839
if (!eq) {
39-
number = Number(Math.round(parseFloat(number) + step * power[gtlt] + 'e6')+'e-6');
40+
// change integer pixels value only on integer pixel
41+
if (unit === 'px' && initialNumber === parseInt(number, 10)) {
42+
number = initialNumber + power[gtlt];
43+
} else {
44+
number = Number(Math.round(parseFloat(number) + step * power[gtlt] + 'e6')+'e-6');
45+
}
4046
}
4147
} else {
4248
number = power[gtlt] + feature_unit[name];

test/fixtures/min-max.output.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@media screen and (min-width: 500.001px) and (max-width: 1199.999px) {
1+
@media screen and (min-width: 501px) and (max-width: 1199px) {
22

33
}
44

5-
@media screen and (min-width: 500.001px) and (max-width: 1199.999px) {
5+
@media screen and (min-width: 501px) and (max-width: 1199px) {
66

77
}
88

@@ -26,11 +26,11 @@
2626
}
2727

2828
/* height */
29-
@media screen and (min-height: 500.001px) and (max-height: 1199.999px) {
29+
@media screen and (min-height: 501px) and (max-height: 1199px) {
3030

3131
}
3232

33-
@media screen and (min-height: 500.001px) and (max-height: 1199.999px) {
33+
@media screen and (min-height: 501px) and (max-height: 1199px) {
3434

3535
}
3636

0 commit comments

Comments
 (0)