Using CSS in Laravel views?(在 Laravel 视图中使用 CSS?)
问题描述
我刚开始学习 Laravel,可以做控制器和路由的基础知识.
I've just began learning Laravel, and can do the basics of a controller and routing.
我的操作系统是 Mac OS X Lion,它位于 MAMP 服务器上.
My OS is Mac OS X Lion, and it's on a MAMP server.
我的来自 routes.php 的代码:
My code from routes.php:
Route::get('/', function() {
return View::make('home.index');
});
Route::get('businesses', function() {
return View::make('businesses.index');
});
Route::get('testing', function() {
return View::make('testing.index');
});
Route::get('hello', function() {
return "<h3>Hello world!</H3>";
});
这行得通,视图显示完美,但是"我想要尝试在视图中包含 CSS,我尝试在目录中添加指向样式表的链接,但页面将其显示为默认值浏览器字体,即使 css 在 HTML 中!
That works, the views display perfectly, ''however'' what I want to try and do is include CSS within the views, I tried adding in a link to a stylesheet within the directory but the page displayed it as the default browser font even though the css was in the HTML!
这是视图文件夹中企业的 index.php:
This is index.php from businesses within the views folder:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<p>Business is a varied term. My content here.
我尝试在我的其他视图文件夹(测试)中使用 Blade 模板引擎来显示 CSS,但是尽管 CSS 在测试文件夹中,但仍然没有显示 CSS!
I tried using the Blade template engine in my other views folder (testing) to display CSS but again the CSS did not show despite it being in the testing folder!
我怎样才能克服这个问题,变得更好 - 因为我正在慢慢学习这个框架.
How can I overcome this problem, and get better - as I'm slowly learning this framework.
推荐答案
把你的资产放到公用文件夹中;例如:
Put your assets in the public folder; e.g.:
public/css
public/images
public/fonts
public/js
然后,要使用 Laravel 访问它们,请使用:
And then, to access them using Laravel, use:
{{ HTML::script('js/scrollTo.js'); }}
{{ HTML::style('css/css.css'); }}
或者:
{{ URL::asset('js/scrollTo.js'); }}
{{ URL::asset('css/css.css'); }}
此语法将自动生成正确的路径(例如,`public/js/scrollTo.js').
This syntax will automatically generate the correct path (e.g., `public/js/scrollTo.js').
这篇关于在 Laravel 视图中使用 CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Laravel 视图中使用 CSS?
基础教程推荐
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01