CSS没有显示背景图片

时间:2019-04-27 18:05:55

标签: css vue.js

我正在尝试在Vue项目中使用响应式全屏图像背景,但无法显示图像,并且不确定出现了什么问题,我所看到的大多数示例都使用css我的代码示例

<template>
    <div id="myDiv">

    </div>
</template>

<script>
</script>

<style scoped>
    #myDiv {
        /*background: url('../../Images/Toronto.jpg');*/
        background: url('https://images.pexels.com/photos/374870/pexels-photo-374870.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260');
        height: 100%;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
    }

1 个答案:

答案 0 :(得分:1)

HTML和正文标记必须具有min-height: 100%

如果您无法执行此操作,则另一种选择是应用min-height: 100vhmin-width: 100vw