Vue.js 2-从body标签中删除初始边距 [英] Vue.js 2 - Remove initial margin from body tag

查看:108
本文介绍了Vue.js 2-从body标签中删除初始边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉,如果这是一个愚蠢的问题,我对Vue还是很陌生.我创建了一个Vue(使用命令 vue init webpack< project-name> )项目,并开始添加组件,第一个组件是导航栏.但是随后我注意到body标签默认具有 margin:8px ,这导致我的页面和浏览器各侧之间始终存在8px的空白.我一辈子都无法弄清楚如何消除这种余量,我尝试使用以下CSS:

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; }

还有

body { margin: 0 !important; }

我尝试将其直接添加到根index.html的样式标签的头部以及我所有组件的样式标签中,但根本无法摆脱.

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.

推荐答案

看来我是个白痴.当我在索引的头中执行 * {} 规则时,直到开始写问题之前,我才真正地没有包含!important ,那时我不记得>!important 放在分号之前或之后.因此,当我在文本编辑器中将其编写,复制到我的问题然后继续执行时,由于某种原因,保存了索引,您知道什么?有效.

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.

因此,总结来说, * {margin:0!important;} 放在index.html头部的样式标签中即可.

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

这篇关于Vue.js 2-从body标签中删除初始边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆