How can I set the width
property of a div
so that it is always a percentage of the browser window's width?
For example,
div
's width is 1536px (80%)div
's width is 1280px (80%)and so forth?
You should use a wrapper div and set it equal to 100% of the browser width, then put the desired div and set it to width:80%
. This will allow you to center your desired div too. (use margin:0 auto
for this.)
Here's a JSFiddle with a demo: http://jsfiddle.net/6Lwpr/
vw: Relative to 1% of the width of the viewport
https://www.w3schools.com/cssref/tryit.asp?filename=trycss_unit_vw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With