How To Target A Specific Page or Post Type ID In Divi with CSS Tutorial by Pee Aye Creative

How To Target A Specific Page or Post Type With CSS In Divi

Sometimes you need to target a specific page or item on a page of your Divi website with CSS. This short tutorial will show you how to do that very easily!

1. Target Individual Pages or Posts With CSS

The best way to target a specific page with CSS in Divi is to first find the ID of the page. This can be found in several ways.

A. Find Page ID From the “Edit Page” slug

The simplest way to find the CSS class of the page you want to target is to find the page ID in the slug of the page editor. This is super easy to find. Just go to the page you want to target, edit the page, and look in the address bar for something like this: https://yourdomain.com/wp-admin/post.php?post=291&action=edit

Do you see any numbers? That’s right! The page ID that you need for your CSS is right there, 291.

So how would this be used? The number gets added to the CSS selector of “.page-id-“ and becomes “.page-id-291”

So an example would be like this:

.page-id-291 {
background: red;
}

Now this page is the only page on your website that will have the background color of red applied to it. This can be very handy for targeting more specific elements on your page like the header or menu item.

NOTE: For blog posts, it will be very similar, but the CSS selector will be “postid-“ instead, so for example “.postid-52”

B. Find Page ID Using the browser’s Inspect tool

This other method is for those how are familiar with the browser inspect tool. When you right-click on your website, you will see something like “inspect” or “inspect element.” Click on that and look for a button in the new, scary-looking code popout that looks like a mouse pointer. Select that pointer and click something on the page. Then, in the code popout, look for something near the top that starts with this:

<body class=”page-template-default page page-id-291 etc. etc.

Did you notice it? There it is, the “.page-id-291” that we need to target this Divi page with CSS. You can apply your CSS the same way as in the previous example.

Again, this is the same for blog posts. Just look for the “postid” on in the code.

Last updated Dec 26, 2022 @ 11:23 pm

Subscribe

Each month we send out a roundup email newsletter with the latest tutorials, product updates, helpful resources, and any other industry or personal news. Occasionally we send an extra separate email here and there if we just can’t wait! So that’s what you will get if you subscribe, and you can always unsubscribe at any time if you just can’t take it anymore :)

Blog Post Optin

Please share this post!

Nelson Lee Miller (aka The Divi Teacher)

Nelson is the owner of Pee-Aye Creative in the beautiful state of Pennsylvania. He loves helping small businesses, exploring outdoors, building websites with Divi, and teaching others.

Leave A Response!

By commenting you agree to our Blog & YouTube Comments Policy

0 Comments

Submit a Comment

Your email address will not be published.

Recent Posts

0

Your Cart