Jin
Jin

Reputation: 1439

How to know width = ? px = % in HTML/CSS

I am learning HTML / CSS, I am currently doing code to practice with my lesson, but I am wondering about that one issue about px and % when setting the width of the web page. I want to know that: width = 1px =?%; can anyone help me, I already searched but there does not have any answer, thank you so much

Upvotes: 0

Views: 306

Answers (1)

sebasaenz
sebasaenz

Reputation: 1956

The percentage is always calculated in relation to the containing block. So if for example the containing block is 100px and you want the width of your contained div to be 1px but want to express it in terms of percentage, then you would have to right it as 1%.

TL;DR: for a containing block of 100px width: 1px = width: 1%.

Upvotes: 3

Related Questions