1
<body onload="myFunction()" style="margin:0;height:850px">

How can I put @media queries in there? I tried in CSS but it does not work. I think it would be easier if I put it in the HTML body tag.

Brett DeWoody
  • 59,771
  • 29
  • 135
  • 184

2 Answers2

4

To make @media queries work you need to put a <meta> viewport tag in the head, like this:

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

If you do that @media queries should work in either a seporate CSS stylesheet or through <style> tags.

https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag

James Douglas
  • 3,328
  • 2
  • 22
  • 43
3

You can inline css styles by using the style tag.

<body>
  <style>
    @media only screen and (max-width: 400px) {
     .body {
       background-color: red;
     }
    }
  </style>
</body>
Kevin Upton
  • 3,336
  • 2
  • 21
  • 24