Hey there everyone, really enjoying Hugo but had a little question if I may.
I notice that most themes place all their CSS in one large file and then reference this file in their layout template. I understand that you can override an entire file via the /static and /layout directories, but this is rather troublesome in the case of CSS with many themes because it would mean that I would need to keep my own maintained copy of the original large CSS file.
For example, let’s check out the casper theme for Hugo:
In this case, I wish to override a few aspects of screen.css which is 1,910 lines long.
The header layout links to these 2 CSS files but doesn’t allow any room for overriding anything without replacing the original screen.css with a new copy that contains minor alternations.
To override the CSS, just add your own CSS file with a link tag after all of those, linking to an appropriate file in /static. See this for more information if you want to replace them completely.
Thanks so much for your reply. I guess this means that we probably have to override the header.html partial to specify the additional CSS link, is that correct?
This is a common problem when users try to customize a theme. In some of my themes I include an option to easily insert custom stylesheets. Maybe you can do a pull request to add the following scheme to the theme:
Inside the config file I assign an array to a variable:
Thank you so so much for your reply. This is similar to what I had in mind, awesome implementation!
It would be awesome if this were to become a standard practice that all theme developers used. Once I choose a theme, I’ll submit a pull request with this feature.
A perhaps more flexible solution for themes would be add an empty “extra-in-head.html” partial. This way, users can put anything into the head by overriding “extra-in-head.html”.
It may for example be that for performance reasons, it is desired to include the css directly in the HTML, thereby eliminating a server request.
Or it may be that the user want to include some css on a specific page. He can then create an “extra-in-head.html” partial which includes the CSS specified in the frontmatter, ie something like this:
frontmatter:
+++
css = "contact"
...
extra-in-head.html:
{{ if eq .Params.css "contact"}}
{{ template "css/contact.html" }}
{{ end }}
{{ if eq .Params.css "about"}}
{{ template "css/about.html" }}
{{ end }}
That would be very cool. Does the default Ananke theme has this parameter available? Is it called custom_css or something else? I can not find it in the example site or in their readme.
If not already in the theme, you can always customize the head partial by creating a duplicate in your project source that will override the theme source via Hugo’s lookup order.
Hi Folks! Thanks for this exchange (and thanks for this great Hugo framework!).
I noticed that I can overwrite a css file of a theme like “hugo-universal-theme” by creating a css directory under the static directory, copy the css file to change and apply my changes there.
Unfortunately, these changes are not taken under consideration when I run hugo server. I have to run hugo and generate the ‘public’ folder to see the css file overwritten.
Is it design this way or is it specific to this theme?
I was just looking for an answer to this very question with the universal theme when I stumbled across this thread.
So, i took a look at universal’s head.html, and saw the following lines after the <link> to the style.[stylename].css:
<!-- Custom stylesheet - for your changes -->
<link href="{{ .Site.BaseURL }}css/custom.css" rel="stylesheet">
So, at least for “universal,” if you copy the theme’s custom.css into your [theme]/static/css directory, you can put your overrides there. When I build the site, it seems to put the appropriate custom.css in the [theme]/public/static/css directory. So, I’m going to put my css overrides in the site’s custom.css.
Yes, I second that Universal theme rocks, they have all the bells and whistles I need, just put custom css in /static/css/custom.css (I copied the corresponding file from the theme tree).
Hi all, not sure I completely understand this thread. But I want to use an example. I have a theme that sets unordered list-style: none. So I get no bullet points. This is good for the page as a whole but I would like to be able to see bullet points on the posts (blog).
My understanding that best practice would be to add a new CSS file with some sort of conditional so that it only does list-style: circle on blog section of the page?
Or maybe use {.inner} to run html stylesheet on the particular blog post that needs the bullet points?
If your question is about specifying CSS conditionally you would either need to use Conditional Logic in a page template or selectively load the CSS file as a resource and use ExecuteAsTemplate.
I am archiving this topic because as I said above things have changed and also people who participated in this discussion may not be around in this forum currently.
If you are still unable to solve your issue then please open a new topic, while following the Requesting Help tips.