在vue组件中使用样式的最佳实践是什么?

亚历克斯·亨特(Alex Hunter):

我正在使用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中做出的行为,也许是范围属性?但是为什么?做什么用的?如何解决?

在此处输入图片说明

Niklesh Raut:

您可能不知道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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

样式组件中“ ThemeProvider”的最佳实践是什么?

在组件内部使用redux状态的最佳实践是什么?

使用 Vue,在多个父组件中使用 Pagination 组件的最佳方法是什么?

我在 Java 中使用大内存的最佳实践是什么?

在ReactJS中使用表单的最佳实践是什么?

在多线程中使用泰坦图的最佳实践是什么?

在OOP中,关于在类中使用“ this”的最佳实践是什么?

在UL标签中使用多个标题的最佳实践是什么

在 Java 线程中使用服务的最佳实践是什么?

在通知中使用选择器的最佳实践是什么

Angular 8 中使用服务数据的最佳实践是什么?

在IntersystemsCaché中使用ENUM的最佳实践是什么?

在Vue JS组件中使用Laravel路由的最佳方法是什么

在Webpack中使用样式表的最佳方法是什么?

在React中使用嵌套组件的最佳实践

使用 CompositeDisposables 的最佳实践是什么

RxSwift:使用DisposeBag的最佳实践是什么?

在 Vue.js 中使用 $state 的最佳方式是什么?

在Firestore中使用“集合组查询”的多租户应用最佳实践是什么?

在Ionic Framework中使用带有oAuth的ASP.NET Web Api的最佳实践是什么?

在Zend Framework中使用工具功能的最佳实践是什么

在多对多关系中使用 Firebase 建模 SaaS 应用程序的最佳实践是什么

在require native中使用require()和import的最佳实践是什么?

在Ruby on Rails中使用ActionCable更新多个div的最佳实践是什么?

在Swift中使用NSCoding在分层类中实现数据持久化的最佳实践是什么?

React 导入大型静态数组以在选择字段中使用的最佳实践是什么?

在 hbase 中使用过滤器进行行计数的最佳实践是什么?

C# - 在 Windows 应用程序中使用 DB 时的最佳实践是什么?

在 C 中使函数“独立”的最佳实践是什么?