In my project that is developed in laravel, i am trying to use a style.css file using blade engine. but it's not working for me anybody have better idea let me know.
Here is my code sample
<link href="{{ asset('/css/style.css')}}" rel="stylesheet" type="text/css">
it's tag is not working but when i'm us following it's working.
<link href="{{ asset('public/css/style.css')}}" rel="stylesheet" type="text/css">
now i want to now best practices of adding css files and how to include other files. like i've file header.blade.php it hold all css file link now i want to include header.blade.php in home.blade.php file both file in view directory.
Placed your css file inside laravel_project/public/css folder and use the link it into your view like:
<link href="{{asset('css/style.css')}}" rel="stylesheet" type="text/css"/>
I think this will help you Thanks.
I think your style.css is stored in public/css directory thats why it allow second you have provided.
And now your header.blade.php holds all your css files so you have to follow laravel's structure in layout if u have app.blade.php or any layout then its perfect otherwise you have to make it own
Sample app.blade.php (stored at views/layout/)
<!DOCTYPE html>
<html>
#include('layouts.partials.header') // path to your header.blade.php
#yield('content')
#include('layouts.partials.footer') // path to your footer.blade.php
</html>
Now this is your layout and you can use your layout and your header as well as footer in your view file like i am creating one blog_list.blade.php which is stored at views directory
blog_list.blade.php
#extends('layouts.app') // we are extending app.blade.php
#section('content')
// here whatever your content
#endsection
You can find more details on laravel's official site laravel-5.4
I hope it helps you. thank you.
Related
I want to apply margin-bottom on #createNewBook, I added a CSS file in laravel by using <link rel="stylesheet" href="/assets/css/style.css">. But it's not working. Can anyone tell me how to add a CSS file to my laravel project?
This is my HTML code in laravel:
This is CSS code:
This is my directory format:
And this is the output:
Put the assets folder in public then in the blade file use this syntax to load css
{{asset('assets/css/style.css')}}
You have to put your assets folder into the public folder because only the things in the public folder are accessible publicly.
And then in the blade.php file use the following syntax to load CSS.
<link rel="stylesheet" href="{{asset('assets/css/style.css')}}">
#extends('layouts.app')
does not work on some of my web pages. it just shows the content without the layout. why is this happening?
I already tried making a new layout folder and calling it but still some pages still doesn't show the layout.
both show.blade.php and create.blade.php doesn't display the layout
it only shows like this
app.blade.php
this is the navbar.blade.php
Your CSS file maybe not loading properly.
change your app.blade.php file like below,
<link rel="stylesheet" href= "/css/app.css" >
you might what to try this:
<link rel="stylesheet" href="{{ asset('css/app.css') }}" />
In my case this fixed it (had to add public):
href="{{ asset('public/css/app.css')
If your style css not working on every page, try adding it with the asset helper;
This help me to solve exactly the same problem. You can find in Laravel Docs. ;
https://laravel.com/docs/8.x/helpers#method-asset
So I have a webpage where I use the same header/footer for every page:
<?php include 'header.php?>
In header link to css looks like this:
<link rel="stylesheet" type="text/css" href="styles.css">
they both are in the same folder.
Problem:
When I try to load page in another folder (products/page.php) - the assets wont load properly. I put a link to header like this:
<?php include '../header.php' ?>
header and footer loads properly but the assets defined in them do not.
How can I fix the paths so I would not need to copy same files to every folder.
Sorry for noob question :)
A pssible solution is to use absolute paths:
<link rel="stylesheet" type="text/css" href="/styles.css">
This way your assets are indepent to your phps structure.
I want to add a css file to my template. I created the template.php into the folder : kohana-v3.3.5\application\views. Into this folder, I created an other folder called "css" and inside it, there is my styles.css with some code.
For now, my template file is :
<html>
<head>
<link href="/css/bootstrap-3.3.6-dist/css/bootstrap.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
</head>
<body>
<div class="row">
<div class="col-md-12 banner">
Persyst
</div>
</div>
<?php echo $content; ?>
</body>
</html>
I don't understand why the links for my css files aren't working.
I saw something with HTML:style() but it doesn't work either.
Thanks for your help !
Using HTML::style() is a good idea. The reason why it fails is because you put the assets folder inside the template folder. The latter is outside of web access (or should be) and is only used internally.
Kohana routes everything through the index.php file, so this is the level your stylesheets, scripts and images belong.
<html>
<head>
<?php
print HTML::style('vendor/bootstrap-3.3.6-dist/css/bootstrap.css') ."\n"
. HTML::style('assets/css/styles.css');
?>
With a directory structure like
application
modules
system
assets
css
js
vendor
bootstrap
I have the following route which loads the page but the css of the page doesn't loads.
Route::get('admins', function () {
return view('admins/index');
});
In the contrast the following route loads the same page but here I added index and the page loads correctly. but I also adds index with admins in the browser address bar.
Route::get('admins/index', function () {
return view('admins/index');
});
I am calling css files in the views like:
<link href="../assets/css/animate.min.css" rel="stylesheet" />
I searched for the solutions but didn't got anything.
For Laravel 4 & 5:
<link rel="stylesheet" href="{{ URL::asset('assets/css/animate.min.css') }}">
URL::asset will link to your project/public/ folder, so chuck your scripts in there.
Note: You'll need to be using blade templates to use this. All Blade templates should use the .blade.php extension.
i am using code like below for css and js :
<link rel="stylesheet" href="{{ asset('/') }}css/menu-style.css">
And css directory is in my "project/public" directory.