【问题标题】:In Next.js, how to create a bg image that covers the entire browser window在 Next.js 中,如何创建一个覆盖整个浏览器窗口的 bg 图像
【发布时间】:2020-06-02 00:10:06
【问题描述】:

在下图中,我们必须将高度 100% 应用于 html 和 body 标签。但是如何在 next.js 组件中做到这一点??

参考[1]:https://i.stack.imgur.com/K1r9l.png

[2]https://www.w3schools.com/howto/howto_css_full_page.asp

“mainImage.jsx”

import React from 'react';
import './mainImage.css'

export default ()=>(
    <div>
        <div className="bg"></div>
    </div>
)

“mainImage.css”

.bg {
    /* The image used */
    background-image: url("/public/jeep3.jpg");

    /* Full height */
    height: 100vh;

    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

应用高度后:100vh;我只显示长度而不是图像的空 div。

【问题讨论】:

  • 您好,请问可以添加基本代码吗?

标签: html css reactjs next.js


【解决方案1】:

您需要将高度值更改为:

.bg {

height:100vh;

}

【讨论】:

    猜你喜欢
    • 2021-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多