5

I'm trying to figure out the best place to keep my one master CSS file in craft.

I had the CSS linked in my template as

link rel="stylesheet" href="../craft/css/master.css">

But now Blog entries can't get to it, as they are looking in www.domain.com/index.php/blog/craft/css/master.css now.

Is there a better place to put the CSS, or a better way to link to it in templates?

1
  • Are you referring to the site's CSS or like special CSS you wrote to edit the way something looks in the CMS?
    – Ryan
    Commented Sep 29, 2017 at 22:05

3 Answers 3

11

In most cases, the best place to store CSS is in a publicly accessible directly, not managed by Craft at all. Such as:

public/assets/css/master.css

Storing your CSS and other front-end assets outside of Craft reduces the overhead of accessing those files. While Craft allows you to store css files in your Craft templates folder, there is additional overhead to access those files as they need to be processed by Craft.

0
2

I had a similar issue...my Craft3 blog pagination was losing the link to my main.css file after the first page, so all content would show but styling disappeared after the main blog index page. As suggested above, I now have my css.main in /web/css/main.css, and all of the pagination and styling works perfectly.

1

As Ben said, you want them in the public folder. Also, you may want to use the Twig tag {% includeCssFile ...%) instead of the HTML <link rel="stylesheet" ...>.

It outputs the same way, but it works better once you start having different template folders on your site. Documentation can be found here: https://craftcms.com/docs/templating/includecssfile

1
  • I didnt know about the includeCSSFile. I ended up changing my css src to ../public/master.css so that all my other templates could access it
    – kingkelly
    Commented Oct 4, 2017 at 2:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.