欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > vue3 解决背景图与窗口留有间隙的问题

vue3 解决背景图与窗口留有间隙的问题

2024/10/23 3:47:27 来源:https://blog.csdn.net/scongx/article/details/142992994  浏览:    关键词:vue3 解决背景图与窗口留有间隙的问题

        需要实现一个登录界面,login.vue的代码如下:

<script>
import { ref } from 'vue';export default {setup() {return {};},
};
</script><template><div id="login-container" class="login-container"><div id="container-left" class="container-left"></div><div id="container-right" class="container-right"></div></div>
</template><style scoped>
.login-container {display: flex;flex-direction: row;background: url('../assets/loginBk.jpg') no-repeat center;background-size: cover;height: 100vh;width: 100vw;justify-content: center;align-items: center;
}.container-left {flex: 2;height: 100%;width: 100%;
}.container-right {flex: 1;height: 100%;width: 100%;
}
</style>

        可以看到已经把背景图的宽高分别设置为100vw和100vh了(占满整个可视窗口),但实际运行时发现图片和窗口之间留一定间隙且出现了滚动条:

        于是去看一下检查页面,发现body标签的margin设置为了8px:

         想来应该是index.html中的body标签有默认的margin间隙,于是手动讲margin设置为0:

        改好后发现问题解决了:

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com