php - Laravel CSS 和 Bootstrap 不起作用
问题描述
我创建了一个新的 Laravel 项目并下载了 bootstrap CSS 和 JS 文件,并将 CSS 文件放在 resources/css 中,并将 bootstrap 和 popper 的 JS 文件以及 jQuery 放在 resources/js 和 welcome.blade.php 我链接了 CSS 文件和这样的JS文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Osama The Coder</title>
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
</head>
<body>
<section class="text-danger">
Hello World
</section>
<script src="{{ asset('js/jquery-3.6.0.min.js') }}"></script>
<script src="{{ asset('js/popper.min.js') }}"></script>
<script src="{{ asset('js/bootstrap.min.js') }}"></script>
</body>
</html>
当我打开项目时,它只是没有任何样式或 Bootstrap 字体系列的文本,即使我链接了 app.css 并将红色应用于部分元素,我也没有看到任何变化
解决方案
请按照以下步骤
将所有静态资产放在公共目录中
将资产组织在不同的文件夹中,例如 public/js 用于 js 相关文件,public/css 用于 css 相关文件
然后使用下面的辅助方法访问您的文件
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}"> /* or js files */ <script src="{{ asset('js/jquery-3.6.0.min.js') }}"></script>
推荐阅读
- speech-to-text - 如何将字母拼写到 Google Cloud Speech-to-Text
- hyperledger-fabric - JSON格式的链码的构造函数消息?
- ubuntu - Cloudflare nginx 服务器 nodejs 应用 SSL 错误
- r - 处理情绪的 NA
- spring - responseContainer 的 Swagger 2 注释是什么?
- python - 使用 FastAPI 从下拉菜单中获取数据
- java - JMH + Maven。BenchmarkList 进入错误的 JAR
- python - Tensorflow:对象检测API,加载模型需要很长时间
- angular - TypeError:无法分配给对象“[object Object]”角度的只读属性
- html - 是否可以在 IMG 标签中使用 SVG?