The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Different Colors For Each Category

View previous topic View next topic Go down

Solved Different Colors For Each Category

Post by Genesis on Thu Feb 11, 2016 8:50 pm

My problem is simple. I would like to change the color of each category's header. For example, the first category could be red, the next category below it could be yellow.

Genesis
Helper
Helper

Male Posts : 2331
Reputation : 322
Language : English
Location : Forumountain

http://forumpromocean.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by SLGray on Thu Feb 11, 2016 9:31 pm

Do you mean the backgrounds or the titles?


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.


SLGray
Administrator
Administrator

Male Posts : 36701
Reputation : 2445
Language : English
Location : United States

http://ztwds.forumotion.com/

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Genesis on Fri Feb 12, 2016 9:57 pm

The backgrounds.

Genesis
Helper
Helper

Male Posts : 2331
Reputation : 322
Language : English
Location : Forumountain

http://forumpromocean.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Ange Tuteur on Sat Feb 13, 2016 5:41 am

Hi @Forumedic,

This can be done by using a bit of JavaScript and CSS. Go to Modules > JS codes management > Create a new script

Placement : In the homepage
Code:
$(function() {
  var forum = {
    'Main' : 'category-main',
    'Features' : 'category-features'
  },

  a = $('.forabg'), i = 0, j = a.length, k, txt;

  for (; i < j; i++) {
    txt = a[i].getElementsByTagName('H2')[0].innerHTML.toLowerCase();

    for (k in forum) {
      if (txt == k.toLowerCase()) {
        a[i].className += ' ' + forum[k];
        break;
      }
    }
  }
});

The variable you should focus on modifying is the
Code:
forum
object :
Code:
  var forum = {
    'Main' : 'category-main',
    'Features' : 'category-features'
  },

To the left of the colon is the category name, and to the right of the colon is the class you want added to this category. Make sure to separate these pairs by a comma. Note that the last pair in the object doesn't need a comma, unless of course you add another pair after it. When you're finished editing make sure to save.

After this you can use CSS to modify the category style attributes.
Code:
.category-main {
  background-color:#8C5;
  border-color:#7B4;
}
If necessary, you can use the
Code:
!important
flag to override styles. That is if your rule doesn't take effect.

If any questions let me know. Smile

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Genesis on Sat Feb 13, 2016 8:52 am

Didn't work. Where shoukd I put the "!important"?

I did this:
Code:
.category-main { !important
  background-color:#f04c25;
  border-color:#f04c25;
}

Genesis
Helper
Helper

Male Posts : 2331
Reputation : 322
Language : English
Location : Forumountain

http://forumpromocean.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Ange Tuteur on Sat Feb 13, 2016 9:50 am

It should go at the end of the property value. e.g. :
Code:
selector {
  property:value !important;
  property:value;
}

Info : https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Genesis on Sat Feb 13, 2016 9:54 am

Did it, didn't seem to work either.

Genesis
Helper
Helper

Male Posts : 2331
Reputation : 322
Language : English
Location : Forumountain

http://forumpromocean.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Ange Tuteur on Sat Feb 13, 2016 9:59 am

The URL of your forum this is applied to ?

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Genesis on Sat Feb 13, 2016 10:00 am

I should have put that in the first post, sorry.

http://katalyst.forumotion.com/forum

Genesis
Helper
Helper

Male Posts : 2331
Reputation : 322
Language : English
Location : Forumountain

http://forumpromocean.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Ange Tuteur on Sat Feb 13, 2016 10:03 am

There's an error in the script. Add a comma after this :
Code:
'Features':'category-features'

and this :
Code:
'Discussion':'category-discussion'

and it should be good.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Genesis on Sat Feb 13, 2016 10:08 am

Yes! Thank you very much!

Solved! Smile

Genesis
Helper
Helper

Male Posts : 2331
Reputation : 322
Language : English
Location : Forumountain

http://forumpromocean.com

Back to top Go down

Solved Re: Different Colors For Each Category

Post by Ange Tuteur on Sat Feb 13, 2016 10:28 am

You're welcome !

Topic archived

Have a good weekend. Smile

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum