I am building a blog for myself using Jekyll, however, when I open the page in my browser, the SCSS fails to load. I try to navigate to the SCSS file through my browser but to no avail, the browser believes that the SCSS does not exist.
Here is how I add the stylesheet to the HTML:
<link rel="stylesheet" type="style/css" href="/_sass/_base.scss">
I did this to all of my stylesheets, and yet the it doesn't work.
Does anyone know how to fix this problem? Thank you in advance.
You do not link to stylesheets with an href to "/_sass/_base.scss".
Instead you should do the following:
create another directory to hold your "stylesheet", say, css/.
then add an empty stylesheet with an empty front matter block (required)
---
---
// this is an empty stylesheet named "style.scss"
// use #import here to load partials from your _sass folder
import your partial(s) into the above "stylesheet".
---
---
// this is an empty stylesheet named "style.scss"
// use #import here to load partials from your _sass folder
#import "base";
#import "mixins";
link your HTML page with the stylesheet:
<link rel="stylesheet" type="style/css" href="{{ 'css/style.css' | relative_url }}">
...and done!
Takeaways:
Import files from your _sass into a "dedicated stylesheet".
The dedicated stylesheet must contain the front matter block (can be empty).
Link your HTML file with the dedicated stylesheet.
Linked file has a .css extension even if your source file was css/style.scss or css/style.sass
You may hard-code the markup or use a Liquid construct to link the stylesheet.
When using a Liquid construct, prefer using the relative_url filter instead of using {{ 'css/style.css' | prepend: site.baseurl }} or {{ site.baseurl }}/css/style.css
Related
I am very new to the laravel , i have done login blade file and i included css files but it's not loading css files ,can you please help me where did i mistake ..?
users.blade.php
<link rel="stylesheet" href="{{ asset('resources/css/user.css') }}">
You're trying to access the resources folder, which is not exposed to the public, you'll have to compile your css so it lives in the public folder, which is the folder that anyone(including your frontend) can access using https://your-url.tld/{public file path}. There are 2 ways in which you can have your user.css file available for to your frontend:
One:
You can import your user.css file to the existing resources/css/app.css file:
/* app.css file */
#import "../path/to/user.css";
Two:
You can compile user.css to a separate file, in case you want to use that file specifically on another layout or blade file instead of mixing it globally with the app.css file:
// webpack.mix.js file
mix.js('...')
.css('resources/css/user.css', 'public/css');
Then in your layout file:
// app.blade.php file
<link rel="stylesheet" href="{{ asset('css/user.css') }}">
Hope it helps.
I have a problem with my application not finding my static files. This however only happens on a certain level. As you can see from the code fragments below, the css, images, js, etc works on certain files and not on others. Not sure what I am missing here.
My Stack: Spring Boot, Thymeleaf
Part of my application.yml file:
server:
port: 8090
servlet:
context-path: /myapp
My application public resources directory structure:
/resources
/public
/css
/images
/js
My application template structure and where the styles and images work:
/resources
/templates/index.html (works)
/templates/admin/index.html (works)
/templates/admin/user/admin/showuser.html (does not work)
Code from /resources/admin/fragments/header.html (Used as a header file for other files)
<!DOCTYPE html>
<html>
<head>
<link href="css/mycss.css" rel="stylesheet">
Code from /resources/templates/index.html (works) (Does not include the header.html fragment)
<link href="css/mycss.css" rel="stylesheet">
Code from /resources/templates/admin/index.html (works) (Includes header.html as a fragment using Thymeleaf)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
Code from /resources/templates/admin/user/admin/showuser.html (does not work) (Includes header.html as a fragment using Thymeleaf)
<!--/*/ <th:block th:include="/admin/fragments/header"></th:block> /*/-->
Not sure how to fix this.
Thank you!
When your urls don't begin with a slash /, they attempt to resolve the current directory. For example:
Page: /templates/index.html
Css: css/mycss.css
The browser tries to locate /templates/css/mycss.css
If the cases that don't work:
Page: /templates/admin/user/admin/showuser.html
Css: css/mycss.css
The browser tries to locate /templates/admin/user/admin/css/mycss.css
If you want to make sure your css works everywhere, you need to make sure the link points consistently to the correct location. I'm guessing something like this would work:
<link th:href="#{/css/mycss.css}" rel="stylesheet">
(Using Thymeleaf to add the context, and to make the path absolute.)
Problem:
I have a Hugo site with pretty standard setup. It uses asset pipeline to process SASS. It imports bootstrap, font-awesome, and also uses resources.ExecuteAsTemplate (please do check out main.css file). CSS resources are being generated properly (I checked resources/_gen/assets/scss/sass) but the .css file in public directory is an empty file. I am not able to find any problems in the code. See the code here, site here. I tried creating a new project with same head.html file and .scss files, and it generated CSS resources, and had them in the public directory properly.
Additional info:
Related files:
head.html
main.scss
Currently, I am not using PostCSS; just have the config file created. Would be replacing minify with postCSS on line 13 in head.html once empty .css file problem is solved.
Output of hugo version:
Hugo Static Site Generator v0.57.2-A849CB2D/extended linux/amd64 BuildDate: 2019-08-17T17:57:54Z
I would gladly provide any additional information if required. Please help!
In the head.html file, link tag is:
<link rel="stylesheet" integrity="{{ $css.Data.Integrity }}" href="{{ $css.Permalink }}">
Changing the link tag with following:
<link rel="stylesheet" href="{{ $css.Permalink }}" integrity="{{ $css.Data.Integrity }}">
fixes the issue.
It seems that Hugo requires user to first call .Permalink of the asset and then only other related functions or variables.
See related discussion on Hugo Discourse here.
I install Twitter Bootstrap using composer and can easily include the CSS like this:
<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet">
However, when I install Font Awesome using composer in the same way, I don't see any CSS files added to that folder. The one CSS file created by Font Awesome is in /app/vendor/components/font-awesome.
How do I include the downloaded Font Awesome CSS into HTML?
Thank you.
Just put the downloaded css file inside public/css/ directory and add following line in your view file.
<link rel="stylesheet" href="{{ asset('css/font-awesome.min.css') }}">
And, Make sure your directory structure should like this:
public/css/font-awesome.min.css
public/fonts/
So that, icon will be displayed properly.
I get an Error Message with laravel 5, which I don't understand.
Next exception 'ErrorException' with message 'File build/css/all.css not
defined in asset manifest.
I haven't installed any asset pipeline or something. Just used elixir to compile, minify and version the scss-file to all.css and included it into the master view with <link rel="stylesheet" href="{{ elixir("css/all.css") }}">
What is this 'asset manifest' and how to fix this error?`
The question is of course what you want to achieve.
If you simply put all.css file into the public/css directory and you want to display this file, you can use:
<link rel="stylesheet" href="{{ asset('css/all.css') }}" />
However if you plan to modify this file and you don't want to have caching issues, you can put this all.css file again into public/css then put into gulpfile.js:
var elixir = require('laravel-elixir');
elixir(function(mix) {
mix.version('public/css/all.css');
});
Now you'll need to run:
gulp
in your terminal, and now you can use
<link rel="stylesheet" href="{{ elixir('css/all.css') }}" />
as you previously did in your HTML.
It will create public/build/ folder with rev-manifest.json (this file is missing in your case).
I would recommend you to watch Managing assets Laracasts episode to understand it a bit better.
Same issue here!! I solve it by creating production version of css. I update gulefile.js as bellow,
elixir(function(mix) {
mix.sass('app.scss').version('css/app.css').browserify('app.js');
});
Then run following command which will create rev-manifest.json file in public/build directory.
gulp --production
Good luck!!