我正在使用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中做出的行为,也许是范围属性?但是为什么?做什么用的?如何解决?
您可能不知道body的margin-bottom
应用范围,例如下面的示例,我有意添加margin-bottom
到body并应用了您的样式。
.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; }
body{
margin-bottom:50px;
}
*{padding: 0px; margin: 0px; box-sizing: border-box;}
<body>
<div class="gridContact">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
</div>
</body>
现在,我包括!important
强制使用我的css样式,它起作用了。
.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; }
body{
margin-bottom:50px;
}
*{padding: 0px !important; margin: 0px !important; box-sizing: border-box;}
<body>
<div class="gridContact">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
</div>
</body>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句