I need to design a responsive website that is responsive also when the browser window is resized.
I have added the following code in the head tag:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
And i have included the following styles:
<link rel="stylesheet" type="text/css" media="screen and (min-device-width: 481px) and (max-device-width: 1500px)" href="style.css" />
<link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)" href="mobile.css" />
However when i resize my browser window to a width of less than 480 pixels, still the document is styled using style.css whereas it should have been styled by mobile.css
What am i missing?
max-device-widthrefers to your device resolution, not the window width size, that ismin-widthormax-widthsee here for better understanding.device-widthare used when you want to target mobile devices but not desktop small resized windows.So, if you want your
mobile.cssbe used for mobile devices with screen resolution width less than481pxand also include desktop browsers windows resized to less than481pxthen replace:for:
in your
mobile.cssmedia query rule.