I’m trying to set a background for certain categories/pages. I use the following css code. It actually works. But the background is displayed on all pages. I want it to be displayed only on certain pages.
How do I get this solved?
#content {
background: url(IMAGE URL) repeat center bottom fixed !important;
background-size: cover !important
}
Unfortunately, I can’t find anything on the Internet. What could fix my problem?
3
Answers
Your css selector currently matches all HTML elements with the id "content". If you use this id for multiple elements (which could lead to problems if you use javascript to access these elements by id), then the styles will apply to all those elements. In order to fix this, use a class instead and only add that class to elements you want the style to apply to.
Sample:
Look at the classes of the
<body>
tag in HTML view of your browser. WordPress adds a unique class for every post, calledpostid-xxx
, e.g.postid-231
.So if you want your CSS only applied for pages/posts with e.g. ID 5 and 150, write
Some other ways to find the post ID without looking at the HTML source can be found on https://www.hostinger.com/tutorials/wordpress-post-id
Using body classes can be a solution. Unless any plugin or theme override it. Please see the reference here:
WordPress body classes
For examples, you want to add the background on the post pages, you can change your CSS to:
or for specific post