【问题标题】:Unknown margin in vue js applicationvue js应用程序中的未知边距
【发布时间】:2022-01-08 04:37:22
【问题描述】:

我生成了一个 Vue.JS 项目,但遇到了问题。 实际上,我希望 App.vue 显示在整个页面上,并且我的不同路线使用路由器视图显示在 App.vue 中。

但是,当我尝试在我的 Game 组件的内容上设置边距时,似乎不是我的 Game 组件上而是 App 组件上的边距.

下面是我的两个 ".vue" 文件。

App.vue

<template>
  <div id="app" class="bg-gray-500 h-full">
    <router-view></router-view>
  </div>
</template>

<script>

export default {
  name:'App'
}
</script>

<style>
 
</style>

Game.vue

<template>
    <div>
        <div id="game">
            <div class="bg-white rounded-lg p-6 w-1/2" style="margin-top:10px">
                <h1>Hi</h1>
            </div>
            
        </div>
    </div>
</template>

<script>
    export default {
        name: 'Game'
    }
</script>

<style>
    #game{
        margin : -0px !important;
        height: 100vh;
        top:0;
        background-color:red
    }
</style>

问题是顶部的小白条,它不应该在那里,而是应该有 10px 顶部边距的白卡

编辑(main.js 文件):

import Vue from 'vue'
import App from './App.vue'
import '@/assets/css/tailwind.css' 
import VueCookies from 'vue-cookies'
import VueRouter from 'vue-router'

Vue.config.productionTip = false
Vue.use(VueCookies)
Vue.use(VueRouter)

const router = new VueRouter({
  mode:'history',
  routes: [
    {path: '/home', component: require('./components/Home.vue').default},
    {path: '/', component:require('./components/Game.vue').default}
  ]
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app');

【问题讨论】:

    标签: javascript html css vue.js vuejs2


    【解决方案1】:

    你可以使用边距 ||填充 Vue.js:

    <v-row class="mb-3"> // margin-bottom: 12px !important;
    <v-row class="pt-3"> // padding-top: 12px !important;
    

    参考链接::https://vuetifyjs.com/en/styles/spacing/#how-it-works

    【讨论】:

      【解决方案2】:

      我怀疑它在 body 元素上,而不是在您的组件中。 尝试添加margin: 0; 以查看。

      【讨论】:

      • 谢谢你的回答,我刚试过还是不行
      • 嗯,这很奇怪。此外,margin: -0px; 不会做任何事情,也可以简单地将其设置为margin: 0; 我们可能需要查看整个代码甚至更好,以及活动示例以进一步研究它。如果可能的话。
      • 我编辑了帖子以显示项目中的最后一个文件 main.js。除了配置文件,我什么都没有。我也在使用'tailwindcss' CSS 框架,但是点击检查元素我看不到任何可以解释这个边距的东西。这就是为什么我认为这是 vue.js 中的一个问题
      • 说实话,这可能不是 Vue 的错,许多 HTML 元素都有默认的填充、边距等,这可能与此有关。
      【解决方案3】:

      在 vue.js 应用中,body 元素的默认边距为 8px。 尝试添加这个 css:

      body {
        margin: 0;
       }
      

      【讨论】:

        猜你喜欢
        • 2021-03-18
        • 2015-01-14
        • 2012-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-09
        • 2013-08-22
        • 2021-12-24
        相关资源
        最近更新 更多