Custom css

Everything to do with Joomla! 3.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
mercedes2
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Tue Jul 08, 2014 11:15 pm

Custom css

Post by mercedes2 » Sat Feb 16, 2019 1:37 pm

Hi, I'm new to this forum so please forgive me it this topic has been dealt with but I couldn't find it.
This is my problem!! I am using Cloudbase3 template and when I add a custom style sheet it always appears in the source code before the template css and therefore does not have any effect. How can I place it after existing styles. Thanks in anticipation

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30892
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Custom css

Post by Per Yngve Berg » Sat Feb 16, 2019 5:10 pm

Mod. Note: Relocated the topic to the Templates Forum.

Sorry, don't know that template. I presume you can find the loading of the css files in the templates index.php file.

thekrotek
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Tue Feb 21, 2017 3:46 pm

Re: Custom css

Post by thekrotek » Sat Feb 16, 2019 11:26 pm

The order of CSS files doesn't really matter. What does matter is how you override definitions. If your changes don't have any effect, then you're doing it the wrong way.

annahersh
Joomla! Guru
Joomla! Guru
Posts: 734
Joined: Wed Aug 15, 2018 8:23 pm

Re: Custom css

Post by annahersh » Sun Feb 17, 2019 5:17 am

thekrotek wrote:
Sat Feb 16, 2019 11:26 pm
The order of CSS files doesn't really matter. What does matter is how you override definitions. If your changes don't have any effect, then you're doing it the wrong way.
On the contrary, css file order does matter and will determine if a rule is overridden.

Example
override.css
.title {font-size: 22px;}
core.css
.title {font-size: 16px;}

In such scenario, the core takes precedence. The override will require that the !important rule has to be added in the override .title rule, and that also fails if the core also uses !important.

mercedes2 wrote:
Sat Feb 16, 2019 1:37 pm
when I add a custom style sheet it always appears in the source code before the template css and therefore does not have any effect. How can I place it after existing styles.
How are you placing the .css file? Did you create the template? If the latter is true, use the following in your template's index.php to ensure the file loads after the template.css

Code: Select all

$this->addCustomTag('<link href="'.Juri::root(true).'/templates/'.$this->template.'/css/custom.css" rel="stylesheet" type="text/css" />');

thekrotek
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Tue Feb 21, 2017 3:46 pm

Re: Custom css

Post by thekrotek » Sun Feb 17, 2019 7:37 am

annahersh wrote:
Sun Feb 17, 2019 5:17 am
On the contrary, css file order does matter and will determine if a rule is overridden.

Example
override.css
.title {font-size: 22px;}
core.css
.title {font-size: 16px;}

In such scenario, the core takes precedence. The override will require that the !important rule has to be added in the override .title rule, and that also fails if the core also uses !important.
My point was, that is doesn't matter, when you want to override styles, because they can easily be overridden no matter what. And no, not only placing "!important" can be the way. I'd even suggest to avoid using "!important", especially when CSS modifications are complex. The best approach is to make your definition more strict. For example:

.title -> body .title

The latter will override the original without "!important".


Locked

Return to “Templates for Joomla! 3.x”