Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per page global styles #177

Closed
nvartolomei opened this issue Nov 1, 2016 · 2 comments
Closed

Per page global styles #177

nvartolomei opened this issue Nov 1, 2016 · 2 comments

Comments

@nvartolomei
Copy link

When using gamor's insertRule in a page != from index.js for example and opening index the insertRule will do nothing. If you open the page where you have insertRule with global styles (ie reset) and then navigate to index you will see insertRules being preserved.

I'm looking for a way to add some global styling to html/body, but only for specific pages.

Also looking for a way to add reset to all pages, without re-importing reset for every page. Looks like #88 would help.

@nkzawa nkzawa added the question label Nov 6, 2016
@dstreet
Copy link
Contributor

dstreet commented Nov 8, 2016

Though not terrible ideal, you can have per-page global styles using Head

// pages/first.js

import React from 'react'
import Head from 'next/head'

export default (props) => {
    return (
        <Head>
            <style>{globalStyle}</style>
        </Head>
    )
}

const globalStyle = `
body {
    background-color: red;
}
`
// pages/second.js

import React from 'react'
import Head from 'next/head'

export default (props) => {
    return (
        <Head>
            <style>{globalStyle}</style>
        </Head>
    )
}

const globalStyle = `
body {
    background-color: green;
}
`

When navigating to /first the background will be red. When navigating to /second the background will change to green

@impronunciable
Copy link
Contributor

Now we are using styled-jsx so you can do

<style jsx global>
  This is global :)
</style>

The above example will also work :)

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants