htmlcssmediadevice-width

Can I use device-width in css to get width of the browser in css itself?


I have a doubt that, can I apply/use device-width to style a div instead of giving 100% for a div?

I tried its working but not sure whether its good practice or not.

`

.myDiv{
        width:device-width;
}
instead.
.myDiv{
        width:100%;
}

`

or am I doing it wrong?

Thanks in advance.


Solution

  • Yes, you can do this. There is new css3 style called vh & vw. This calculated the viewport height or weight. You can use to set any height or width to any container. Refer

    http://quirksmode.org/css/viewport.html

    http://css-tricks.com/viewport-sized-typography/

    VH & VW Supported Browser http://caniuse.com/viewport-units

    I hope this helps you.