Skip to content

Commit 84c58ac

Browse files
authored
Function to convert px to rem
1 parent 73cbecb commit 84c58ac

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Function to convert px to rem
3+
description: This function will convert px values to rem values.
4+
author: gihanrangana
5+
tags: sass,function,pixel,rem,px-to-rem,css
6+
---
7+
8+
```scss
9+
@function px-to-rem($px, $base: 16px) {
10+
@return ($px / $base) * 1rem;
11+
}
12+
13+
// Usage
14+
div {
15+
font-size: px-to-rem(12px); // Output: 0.75rem
16+
padding: px-to-rem(16px); // Output: 1rem
17+
margin: px-to-rem(32px) // Output 2rem
18+
}
19+
```

0 commit comments

Comments
 (0)