繁体   English   中英

如何在 Next.js 中将图像设置为背景?

[英]How to Set an Image as Background in Next.js?

我有两个组成部分:

  1. LoginLayout应该是 Login 组件的高阶组合

  2. Login组件是页面

我需要让登录页面有一个图像作为背景。 我尝试通过 CSS 实现这一点,但它不起作用。

这是LoginLayout

export default ({ children, title }) => (

// I tried to add background: url(.../img)) to this login-layout class
  <div className="login-layout">
    <Head>
      <title>Login to Tex</title>
    </Head>
    <div className="login-wrapper">{children}</div>
  </div>
);

这如何在 Next.js 中实现?

如@Deano 所述,确保将 CSS 附加到组件上。

import './style.css';

如果您使用 CSS 模块导入,请改为:

import styles from './MyStyles.module.css';

export default ({ children, title }) => (
  <div className={styles.loginLayout}>
    <Head>
      <title>Login to Tex</title>
    </Head>
    <div className={styles.Login-wrapper}>{children}</div>
  </div>
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM