gpt4 book ai didi

html - 为什么 CSS 文件没有加载到 React 应用程序中

转载 作者:行者123 更新时间:2023-12-04 14:53:46 26 4
gpt4 key购买 nike

我正在构建一个非常简单的 React 应用程序。除了没有加载 CSS 文件外,一切正常,问题出在哪里?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="/animal_fun_facts/src/styles.css" />
</head>
<body>
<div id="root"></div>
<script src="/animal_fun_facts/src/index.js"></script>
<script src="/app.compiled.js"></script>
</body>
</html>

这是文件结构:

enter image description here

最佳答案

其实你可以用很多方法像 css 模块一样,
既然你已经在一个单独的文件中创建了你的样式表,那么让我们把它导入到你的应用程序中使用以下内容:

import React from 'react';
import ReactDOM from 'react-dom';
import './animal_fun_facts/src/styles.css';

关于html - 为什么 CSS 文件没有加载到 React 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68568697/

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