Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vue.js 2 - Remove initial margin from body tag

Tags:

html

css

vuejs2

My apologies if this is a stupid question, I'm still pretty new to Vue. I created a Vue (with the command vue init webpack <project-name>) project and started adding components, the first of which is a navbar. But then I noticed that the body tag has margin: 8px by default which causes there to always be a 8px white space between my page and the browser on all sides. I can't for the life of me figure out how to get rid of this margin, I've tried using the following css:

* { margin: 0 !important; }

And

body { margin: 0 !important; }

I've tried to add this directly into the root index.html's head in style tags and into all my components' style tags but simply can't get rid of it.

like image 532
SeriousLee Avatar asked Jan 13 '18 14:01

SeriousLee


3 Answers

It seems I was an idiot. When I did the *{} rule in my index's head, I never actually included !important until I started writing my question, when I didn't remember if the !important goes before or after the semi-colon. So after I wrote it in my text editor, copied to my question and then carried on I, for some reason, saved my index and what do you know? It worked.

So in conclusion, * { margin: 0 !important; } in style tags in the index.html's head will do the trick.

like image 127
SeriousLee Avatar answered Nov 20 '22 03:11

SeriousLee


Add style for body element in index.html

<style> body { margin: 0 !important; } </style>

example

enter image description here

like image 33
Khem Manapattanachewin Avatar answered Nov 20 '22 02:11

Khem Manapattanachewin


That's probably because of the "scoped" attribute, remove it in the place where you're setting body margin to 0 and it should work out.

like image 1
Rombelirk Avatar answered Nov 20 '22 02:11

Rombelirk