【发布时间】:2020-10-11 18:31:31
【问题描述】:
我正在使用 vue cli 创建项目,但我的样式出现“错误”
我只是测试一个有 3 行 20vh 50vh 30vh 的组件
<template>
<div class="gridContact">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
</div>
</template>
<style scoped>
.gridContact {display: grid; grid-template-areas: 'one' 'two' 'three'; box-sizing: border-box;}
.one {grid-area: one; background: rebeccapurple; box-sizing: border-box; height: 20vh; }
.two {grid-area: two; background: cadetblue; box-sizing: border-box; height:50vh;}
.three {grid-area: three; background: coral; box-sizing: border-box; height: 30vh; }
</style>
还有我的 app.vue
*{padding: 0; margin: 0; box-sizing: border-box;}
我得到了这种风格(需要的风格)
但是如果我刷新页面,我得到了这个破坏样式的空白,然后如果再次重新加载它看起来不错,然后如果我刷新我得到相同的空白,为什么?
在开发者工具上检查这个行为我看到这个属性注入了,当然那个边距不是我插入的,我认为这是在 vue 中做出的行为,也许是作用域属性?但为什么呢?干什么用的?如何解决?
【问题讨论】:
-
您是否使用过开发工具来查看填充该空间的内容?
-
当然,它说的是 html,但正如您在代码中看到的那样,我不明白为什么会发生这种情况@Daniel_Knights
-
我也不明白为什么。尝试在
gridContact上使用height: 100vh,然后在孩子身上使用百分比 -
是的,我也知道,但我认为这是一个 vue 的“错误”,因为我用 vanilla html 做了同样的练习,而那个“错误”没有显示出来,我很想解决这个问题,但我真的想要要知道vue中的真正解释。感谢您的帮助
-
这是因为 vue 应用程序中包含的样式实际上仅适用于应用程序,而不是整个页面。因此,您的“*”规则不适用于页面的正文(至少这是我的猜测)