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>
3
  • 5
    Possible duplicate of How to load up CSS files using Javascript? Commented Jun 1, 2016 at 23:14
  • 5
    Why not use CSS media queries? This takes the JavaScript completely out of it Commented Jun 1, 2016 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);} Commented Jun 1, 2016 at 23:18

1 Answer 1

3

Just use a css media query like so

You can read about media queries here

@media(max-width: 800px) {
    /*
     * enter css here
     */
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.