What is the difference between pixel and percentage? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the difference between pixel and percentage?

How we change pixel into percentage? Like 1% mean 1pixel or 120 = to 1%?

31st Dec 2021, 3:55 AM
Abdul Hannan Khan
Abdul Hannan Khan - avatar
1 Answer
+ 3
• % is relative unit of measurement in css (divide the total width or hight of screen in 100 parts and a single part will be 1%) • px is absolute ( every device may have different pixel of width and height) You can use javascript to cheque how much pixel does 1 percent of screen contain. to get it use the code var width = window.innerWidth; console.log(width/100)
31st Dec 2021, 4:03 AM
Ayush Kumar
Ayush Kumar - avatar