我正在试着设置一个 Box 使用 url 的属性 background 但似乎没有起作用。我创建了一个沙盒来展示这个问题。我添加了一个背景.jpeg本地图像,我设置为框上的背景,但背景图像没有设置为背景。如果我将背景图像设置为某种颜色,比如说“蓝色”,它就会生效。
Box
url
background
如何设置背景 盒子 一个图像?
盒子
https://codesandbox.io/s/great-sun-tqmhb
你可以移动你的 public 文件夹并更改代码,如下所示:-
public
import "./styles.css"; import { Grommet, Box } from "grommet"; export default function App() { return ( <Grommet> <Box background="url('background.jpeg')" height="200px" width="200px" border={{ color: "brand", size: "large" }} /> </Grommet> ); }
解释 :您的 index.html 基础 应用程序的路径(根据CRA内部完成的网页包配置)。它是相对于您检索 .
index.html
Codesandbox Link