How to differently style pages that display posts of different category in WordPress?

Assuming you have one post with only one category assigned, you can edit the single post page (post.php or single.php depending on your theme) to add an HTML ID to the main class. You will have to use the get_the_category() function. Your PHP code will look something like this:

<article id="category-
<?php 
$category = get_the_category();

if ( ! empty( $categories ) ) {
    echo esc_html( $categories[0]->name );   
}
else { echo "default"; }
?>"
class="single-post">
........
.....
</article>

this will create a dynamic id for a post with the category name. Suppose a post has a category “Horror” then the HTML ID for the main div will be “category-horror”. You can use this id in your CSS to add different styles to this on other HTML elements inside this. Something like this:

#category-horror .single-post {
margin-top: 10%; }

Hope this helps.