gpt4 book ai didi

css - 当我提到本地路径时,为什么背景图片没有显示?

转载 作者:行者123 更新时间:2023-11-27 22:43:57 25 4
gpt4 key购买 nike

但是当我从Web URL链接到它时,它确实在使用以下代码和我的文件夹结构

background-image: url('../Images/Image1.jpeg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;


你能帮我吗? This is my folder structure screenshot and the css code above is in the file 'Components'

最佳答案

谢谢大家,我在这里找到了解决方案:https://github.com/facebook/create-react-app/issues/3238。解决方案不是将直接链接传递到图像,而是将图像引用导入一个变量,然后将此变量添加到样式文字中,如下所示:

import styled from 'styled-components';
import img from './img/bg.gif';

const Content = styled.div`
border: 1px solid #000;
background-image: url(${img});
width: 2000px;
height: 2000px;
`;

关于css - 当我提到本地路径时,为什么背景图片没有显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59703956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com