简体   繁体   中英

How browser calculate size for elements with percents width or height

How browsers calculate size for elements with percents width or height? Is it calculated based on size of the parent node? What if parent node does not have explicit size attributes?

Yes it is calculated based on the parent node. Coming to your point if no explicit size has been given to the parent...Actually I have never done this so cannot guide you on that point.

But remember in case of font-size..if you do not specify any size then browsers go for some pre-defined settings. Every browser has a base font size..When you set a custom value of font-size then the browser actually adds or subtracts the values from that base size...

In short:

  1. Yes its calculated on the basis of parent tag.

  2. Its not safe to not give a custom size and rely on browsers pre-defined settings.

  3. If you dont specify something mostly browsers fall back to their pre defined settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM