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

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.css or scripts.js file, would I just create a css/js folder in resources/views folder, and then call to them in my blade.php files like I would normally do in an HTML file when not using Laravel?

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

Or is there a different approach to this in Laravel?

duanjiwei1283
duanjiwei1283 我说的方式有效,但他们确实有一些更复杂的资产管理人员来处理事情,这取决于你的应用程序的复杂程度,所以你可能想先研究一下。
大约 5 年之前 回复

2个回答

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

Use the asset() function to add css, javascript or images into your blade template.

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

<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 Elixir to process your styles and javascript.

doushaizhen1244
doushaizhen1244 一个比另一个短;)asset()函数是一个帮助程序,比使用laravel facade URL :: asset()更短。 结果是一样的。 我想这是个人喜好的事情。
大约 5 年之前 回复
dousigan0499
dousigan0499 资产和URL ::资产有什么区别?
大约 5 年之前 回复

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.

Your css files

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

And js files

<script type="text/javascript" src="{{ URL::asset('js/jquery.min.js') }}"></script>
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问