Next.js Discord

Discord Forum

Global CSS

Answered
Japanese flying squid posted this in #help-forum
Open in Discord
Avatar
Japanese flying squidOP
so im trying to get rid of the small white margin or border around my page (im new to nextjs) so i have a following questions :
1. when i try to add
 global.css
*{
margin : 0;
padding : 0;
}

it gives me following error : [Syntax error: Selector "*" is not pure (pure selectors must contain at least one local class or id)]
whereas be default when you create a next project its global.css has styles on tags and works fine without any errors

2. i tried cathing the html by giving the html tag class name "catchhtml"
 global.css

.catchHtml {
  margin: -8px;
  padding: 0;
}

this does what i expect it to do but i believe this is not the right approach and it creates a horizontal scroll

# other proper approch to achive that expected behaviour shown in the second image would be appreciated thank you
Image
Image

68 Replies

Avatar
u have to apply the rules to your body, this what i always do:
html,
body {
  padding: 0;
  margin: 0;
}
Avatar
Japanese flying squidOP
tried that got the following error :
Syntax error: Selector "html,
body" is not pure (pure selectors must contain at least one local class or id)

  16 | }
  17 | 
> 18 | html,
     |     ^
  19 | body {
  20 |   margin: -8px;
Avatar
?
this is weird
is this your globals.css file?
Avatar
Japanese flying squidOP
global.css file ill try with globals.css file
Avatar
yeah that doesnt matter
and you are importing it in layout?
Avatar
Japanese flying squidOP
eys
yes
here is the content of my global.css
html,
body {
  margin: -8px;
  padding: 0;
}

.page_wrapper :root {
  --white: #ffffff;
  --dim-blue: #e1eafc;
  --blue: #244e97;
}
.page_wrapper {
  box-sizing: border-box;
  font-family: Inter, sans-serif;
  font-feature-settings:
    "liga" 1,
    "calt" 1; /* fix for Chrome */
  font-size: 130%;
  list-style: none;
  text-decoration: none;
  overflow: hidden;
}

i removed the default css styles
Avatar
set margin to 0
Avatar
Japanese flying squidOP
it doesnt do anything
Avatar
are u sure nothing else overrides it
Avatar
Japanese flying squidOP
im not sure but ill try something
only thing i did was completely remove the conent of global.css file and wrote my own css init
and the behaviour that previously tag style was working and now its now is weird
Avatar
add a !important tag
behind the values
Avatar
Japanese flying squidOP
this is my next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;

if this helps
Avatar
and also check the element styles trough the console
has nothing to do with it
do u have anydesk?
ill fix it for u
or try to find the issue
Avatar
Japanese flying squidOP
im on sway arch linux so no
i can host this on github real quick
will that work?
Avatar
send me your codebase
Avatar
Japanese flying squidOP
give me minute
and thankyou for helping
Avatar
no problem!
put it on github
one sec
Avatar
Japanese flying squidOP
wait
wrong repo
here i forget to commit some changes
Avatar
one sec
Avatar
Japanese flying squidOP
sure
Avatar
basically this is not how css modules works
Image
Avatar
Japanese flying squidOP
is the error because of this
Avatar
yes
Answer
Avatar
@Japanese flying squid check pull request
Avatar
Japanese flying squidOP
sure
Avatar
did this resolve your issue
?
Avatar
Japanese flying squidOP
no i get the same error
Avatar
did u refetch from git
and pull
Avatar
Japanese flying squidOP
yes is it working for you???
Avatar
yes
whats the error?
Avatar
Japanese flying squidOP
Syntax error: Selector "html,
body" is not pure (pure selectors must contain at least one local class or id)

1 | html,
| ^
2 | body {
3 | margin: 0;
same
Avatar
on /home?
Avatar
Japanese flying squidOP
everywhere
wait
Avatar
Japanese flying squidOP
hey thankyou so much its working
i misunderstood the css modules
Avatar
Japanese flying squidOP
hey the issue was me importing the global css two times
removing a single import is also working
Avatar
👍
Avatar
@Japanese flying squid u can mark my answer as solution btw
Avatar
Japanese flying squidOP
sure