0

Would it be possible for me to do something like

<link href="nav.css" type="text/css" rel="stylesheet" />

in this?

<script>
    if (screen.width <= 800) {
        Link to css here!
    }
</script>
  • 5
    Possible duplicate of [How to load up CSS files using Javascript?](http://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript) – U-DON Jun 01 '16 at 23:14
  • 5
    Why not use CSS media queries? This takes the JavaScript completely out of it – KevBot Jun 01 '16 at 23:15
  • `if (something){var link = document.createElement("link");link.setAttribute("href", "nav.css");link.setAttribute("type", "text/css");link.setAttribute("rel", "stylesheet");document.getElementsByTagName("head")[0].appendChild(link);}` – chiliNUT Jun 01 '16 at 23:18

1 Answers1

3

Just use a css media query like so

You can read about media queries here

@media(max-width: 800px) {
    /*
     * enter css here
     */
}
rhys_gbs
  • 409
  • 2
  • 7