Laravel 5:添加自定义样式/脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31726246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:05:32  来源:igfitidea点击:

Laravel 5: adding custom styles/scripts

phplaravellaravel-5

提问by Lansana Camara

This is kind of a stupid question, and I've looked around for similar answers and found some, however they are a bit more specific than what I am asking.

这是一个愚蠢的问题,我四处寻找类似的答案并找到了一些,但是它们比我要问的要具体一些。

Say I want to include a custom styles.cssor scripts.jsfile, would I just create a css/js folder in resources/viewsfolder, and then call to them in my blade.php files like I would normally do in an HTML file when not using Laravel?

假设我想包含一个自定义styles.cssscripts.js文件,我是否只是在resources/views文件夹中创建一个 css/js 文件夹,然后在我的blade.php 文件中调用它们,就像我在不使用 Laravel 时通常在 HTML 文件中所做的那样?

Example: <link type="text/css" rel="stylesheet" href="css/styles.css">

例子: <link type="text/css" rel="stylesheet" href="css/styles.css">

Or is there a different approach to this in Laravel?

或者在 Laravel 中有不同的方法吗?

回答by P??

Put your css files into the publicfolder like public/css/styles.css

将您的 css 文件放入public文件夹中,例如public/css/styles.css

Use the asset()function to add css, javascriptor imagesinto your blade template.

使用该asset()功能将css,javascript或添加images到您的刀片模板中。

For Style Sheets

对于样式表

<link href="{{ asset('css/styles.css') }}" rel="stylesheet" type="text/css" >

or

或者

<link href="{{ URL::asset('css/styles.css') }}" rel="stylesheet" type="text/css" >

For Javascript

对于 Javascript

<script type="text/javascript" src="{{ asset('js/scripts.js') }}"></script>

or

或者

 <script type="text/javascript" src="{{ URL::asset('js/scripts.js') }}"></script>

You may also be interested to have a look at Laravel's Elixirto process your styles and javascript.

您可能也有兴趣查看 Laravel 的Elixir来处理您的样式和 javascript。

回答by Jigs Virani

put your style.css file in inside css folder named: /css AND your js file inside js folder named: /jsput below code in your html file.

将您的 style.css 文件放在名为:/css 的 css 文件夹中,并将您的 js 文件放在名为:/jsput 的 js 文件夹中,放在您的 html 文件中的代码下方。

Your css files

你的 css 文件

<link rel="stylesheet" href="{{ URL::asset('css/yourstylesheet.css') }}" />

And js files

和js文件

<script type="text/javascript" src="{{ URL::asset('js/jquery.min.js') }}"></script>