在Laravel视图中使用CSS? [英] Using CSS in Laravel views?

查看:288
本文介绍了在Laravel视图中使用CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的操作系统是Mac OS X Lion,它在MAMP上

我的代码来自routes.php:

:get('/',function(){
return View :: make('home.index');
});

Route :: get('business',function(){
return View :: make('business.index');
});

Route :: get('testing',function(){
return View :: make('testing.index');
});

Route :: get('hello',function(){
return< h3> Hello world!< / H3>;
});

这很有效,视图显示得很完美,但'''我想尝试的是包括在视图中的CSS,我尝试添加一个链接到目录中的样式表,但是该页面显示它为默认浏览器字体,即使css在HTML中!



这是来自views文件夹中的商家的index.php:

 < head> 
< link rel =stylesheettype =text / csshref =mystyle.css>
< / head>

< p>商业是一个不同的术语。我的内容在这里。

我尝试在其他视图文件夹(测试)中使用Blade模板引擎来显示CSS, CSS不会显示,尽管它在测试文件夹中!



我如何克服这个问题,变得更好 - 因为我正在慢慢学习这个框架。 >

解决方案

将您的资产置于公共文件夹中

  public / css 
public / images
public / fonts
public / js

他们用Laravel调用它

  {{HTML :: script('js / scrollTo.js' ); }} 

{{HTML :: style('css / css.css'); }}


I've just began learning Laravel, and can do the basics of a controller and routing.

My OS is Mac OS X Lion, and it's on a MAMP server.

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>";
});

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!

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.

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

public/css
public/images
public/fonts
public/js

And them called it using Laravel

{{ HTML::script('js/scrollTo.js'); }}

{{ HTML::style('css/css.css'); }}

这篇关于在Laravel视图中使用CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆