Jump to content

Theme Tip: Styling specific elements on specific pages


Recommended Posts

  • Administrators

This applies to both 4.2 and 4.1 versions of IPS.
 

Occasionally you'll want to style a specific element on a specific page of your community - maybe you want to change how topic titles are shown inside a topic, or do something specific to the styles used in activity streams, without also altering other screens where the same elements are used.

Your first instinct might be to open the template editor and add some custom classnames so you can style them. This would certainly work, but the downside is your template is now customized, so any future IPS4 updates would leave the template out of date. Not ideal by any means.

Instead, you can use some helpful attributes that IPS4 adds to the body element, and then build a CSS selector around them. There's four attributes, and they always reference the current page the user is on:

  • data-pageApp - The application key (e.g. core, forums, cms etc.)
  • data-pageModule - The current module with the application (e.g. pages)
  • data-pageController - The current controller within the module (e.g. topic, pageetc.)
  • data-pageLocation - Either admin or front.

So let's say we want to change how the .ipsPageHeader element looks within topic view. Our selector would look like this:

body[data-pageapp="forums"][data-pagemodule="forums"][data-pagecontroller="topic"] .ipsPageHeader {
	...your styles
}

If you don't want to be that specific, you can just use the attributes you need. For example, if you want to change all .ipsPageHeader styles in the Forums app, you'd do:

body[data-pageapp="forums"] .ipsPageHeader {
	...your styles
}

Tip: If you don't know the correctapp/module/controller for the page you're on, you can find out by visiting the page and then viewing the page source. You'll see these attributes in the body tag near the top.

And as always, be sure you add your CSS to custom.css to keep your upgrades easy.

https://invisioncommunity.com/4guides/themes-and-customizations/tips-tricks_362/targeting-elements-on-specific-pages-with-css-r179/

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...