Keyword

Custom CSS for specific category

More
12 years 9 months ago #60574 by Paolo
Custom CSS for specific category was created by Paolo
Hi I've been trying for some time to create extra text areas on my joomla site (on which I'm running K2) and just now had the brilliant idea to simply display several categories in the same page and then move each category where I want by changing the CSS.

So my question is, how do I refer to a category whose id is 6 in CSS?

Please Log in or Create an account to join the conversation.

More
12 years 9 months ago - 12 years 9 months ago #60575 by Jiliko.net
Replied by Jiliko.net on topic Re: Custom CSS for specific category
Hi,

By displaying several categories in the same page, you mean subcategories ?

If yes, you have to create a specific K2 template and update the 'category.php' file to add the category id to the category container and then be able to customize the css.

In 2.4.1, subcategory container is set like this :
<div class="subCategoryContainer<?php echo $lastContainer; ?>"<?php echo (count($this->subCategories)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('subCatColumns'), 1).'%;"'; ?>>
                                <div class="subCategory">

You can transform it like this :
<div class="subCategoryContainer<?php echo $lastContainer; ?> subCategory<?php echo $subCategory->id; ?>"<?php echo (count($this->subCategories)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('subCatColumns'), 1).'%;"'; ?>>
                                <div class="subCategory">

You now have a specific class 'subCategory#id#' for each subcat. Let's say you want to customize the subcat with id 45 :
div.subCategory45 {background: #ccc;}

Olivier

Please Log in or Create an account to join the conversation.

More
12 years 9 months ago #60576 by Paolo
Replied by Paolo on topic Re: Custom CSS for specific category
Do I have to create a new template? Or can I get away with just editing the category.php file?

Please Log in or Create an account to join the conversation.

More
12 years 9 months ago #60577 by Jiliko.net
Replied by Jiliko.net on topic Re: Custom CSS for specific category
It's always better to create a new template, just follow the link in my signature...

Olivier

Please Log in or Create an account to join the conversation.

More
12 years 9 months ago #60578 by Paolo
Replied by Paolo on topic Re: Custom CSS for specific category
Just to try first I commented out the current subCategorycontainer div and added the one you gave me. It doesn't seem to work whether I then add commands to the joomla template's css nor to the k2 css.

Am I supposed to see the sub-category ID if I view the page's source?

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum