1
Even using the function body_class()
which returns the page name or the id
by applying a certain rule in css
some elements in other pages change, for example:
Home:
<body <?= body_class(); ?>> <!-- retorna uma string "home" -->
<div class="hero">
<h1 class="title">Titulo</h1>
</div>
...
Contact page:
<body <?= body_class(); ?>> <!-- retorna uma string "page-id-5" -->
<div class="hero">
<h1 class="title">Titulo</h1>
</div>
...
When using the css
I always try to use the first class that is in body
, that is to say:
.page-id-5 .hero .hero-body .title {
color: white;
}
But even so this rule is being applied on the page home
, what is the best way to separate the css's
between pages on wordpress
?
With this data you posted will not be able to reproduce the problem. It must be something specific to your code. Try playing in a simple example and update the question.
– bfavaretto
Why do you think it doesn’t stop to reproduce? This is exactly the problem I’m facing, the
title
which is inside the "tree" of.page-id-5
is applying in places where they are not in the css hierarchy (starting with.page-id-5
)– RFL
Because if you don’t have a class
page-id-5
above.hero .title
there is no way for the CSS to apply the selector.page-id-5 .hero .title
.– bfavaretto
@bfavaretto put up a print for you to see.
– RFL
Look at the image selector you posted, it’s different from what you described in the question.
– bfavaretto
I’ve already added the
hero-body
in the question.– RFL
That’s not the difference, in the image has a comma that does not have in the question. It makes all the difference, isolates the
.title
.– bfavaretto
understood, I thought when using the comma inside the selectors that would select the
hero-body
and thetitle
in the same order of parent selectors.– RFL