Style members sections using a unique CSS ID
February 10th, 2007How many times have you wished you could style things differently for members than the public on your Joomla! site? Well, we just had a project that it was mandatory, so we set out to come up with some code to allow us to style the CSS separately. This is how it’s done…
Insert this PHP code just below your body tag to add an id called #members only when someone is logged in.
<?php if ( $my->id ) { echo "<div id=\"members\">"; } else { }; ?>
and add this just above the end body tag in your template…
<?php if ( $my->id ) { echo "</div>"; } else { }; ?>
You may now use some creative CSS to style things differently for members. For example, if you have a white header for the public, you can change it to red when members log in by using the following CSS…
#members #header {background:#990000}
If for some reason it doesn’t change then try adding !important on the end of the color and it will override any cascading issues.
I hope you find this little piece of code useful for your Joomla! projects. I know it has given us a LOT more control over our Joomla! pages. Enjoy!
Developer Center