Site logo

Archived topic

Adjust line height for certain categories or individual posts

7 replies · Started by victor on May 8, 2020

Viewing posts 1–8 of 8

I was wondering if there’s an easy way to adjust line height of text for certain posts. For example, some of my posts are a bit ugly when I applied a global line height to all blog posts – is there a way to edit it for only certain categories or individual posts?

Use the post id for posts:

.post-601 {
    line-height: 1.4;
}

For categories, use the category slug prefaced by .category-

.category-mycategory {
   line-height: 1.8;
}

Thanks for that. However, I notice it also effects the excerpt of the post. Is there a way to just have it effect the contents inside instead?

Hi there,

( thanks Mikeb :) ) you can target the .single body class like so:

.postid-601.single {
    line-height: 1.4;
}

Hey David, thanks for your addition as well! Unfortunately, it didn't seem to have any effect on the contents inside of my post - yes, I made sure it was the correct post #!

This worked for your Nachos post:

.postid-305.single {
    line-height: 1.4;
}

I did update the post earlier when is spotted it was post-601 and should have been postid-601

Works great! Thank you!

I am wondering how you figured out how to use .single attached to the postid? How would you go about learning how to access other parts of certain posts? I know there's a bunch of CSS stuff in the contents part of the file, so I guess I'd have to play with that.

Curious, if I wanted to access the excerpt/description of a column image in a post, how would I do that? For example, in my review ice cream posts, I have little excerpts underneath the pictures.

WordPress adds various Classes to the <body> tag - you can see those in place by Right Click > Inspect the page.

You can style the captions using this CSS:

.wp-block-image figcaption {
/* your styles here */
}
This archived topic is closed to new replies.