Rohan Negi Rohan Negi - 6 months ago 12
CSS Question

I have a div inside another div with specific width but I want the child div to have width in percentage with browser screen size not its parent div?

I have a div inside another div with specific width but I want the child div to have width in percentage with browser screen size not in percentage with its parent div, meaning when I set the width of the child div to 50%, I want its size to be 50% of the browser screen not 50% of its parent element, I don't want to remove it from the parent-child its important, any way to achieve this without removing it from being a child ?

P.S- Please no answer in JQuery. Either CSS or Javascript. If it is achievable by css it would be really great, but javascript will also be fine.

Answer

You can use VW (ViewPort Width). Example :

.child {width : 50vw}
Comments