Home › Forums › Support › CSS code from the Geek theme doesn’t work when I copy it to use on another site
- This topic has 11 replies, 3 voices, and was last updated 6 months, 1 week ago by
David.
-
AuthorPosts
-
September 6, 2022 at 2:03 pm #2335288
Sue
The problem that I’m having is on the Blog archive page. After copying the CSS code from the Geek theme to the test site the categories list stops displaying horizontally. In fact, when I inspect the code, I can’t find any reference to .gp-container.category-filter which is where I believe the styling should happen.
Any thoughts on why this is happening?
My system:
GeneratePress version 3.1.3 (theme)
GeneratePress Premium 2.1.2 (plugin)
GenerateBlocks version 1.5.4 (plugin)
WordPress 6.0.2
Running on Local. No other active plugins except the ones above.On MyGPressEx – Local
I’ve installed the Geek theme from the GeneratePress library.On JFS CSS test – Local
I’ve installed a copy of JFS. The production site is running WooCommerce. I have deactivated all plugins except the ones mentioned above.Here is the code that came with the Geek theme. I’ve added it to the JFS CSS test site.
/* GeneratePress Site CSS */
.dynamic-content-template:nth-child(even) .gb-grid-wrapper {
flex-direction: row-reverse;
}
.gb-button-wrapper .blog-term-button:last-child {
border-right-style: none;
margin-right:0;
}
.gb-container.category-filter .wp-block-categories-list{
list-style: none;
display: flex;
justify-content: space-around;
}
.gb-container.category-filter .wp-block-categories-list li.current-cat a {
color: var(–base-3);
}
@media (max-width: 768px) {
.gb-container.category-filter .wp-block-categories-list {
flex-direction: column;
}
}
/* End GeneratePress Site CSS */September 6, 2022 at 5:45 pm #2335381Fernando Customer Support
Hi Sue,
May you provide the link to the site in question?
You may use the Private Information field for this: https://docs.generatepress.com/?s=private+information
September 8, 2022 at 6:47 am #2336992Sue
Here you go.
September 8, 2022 at 7:01 am #2337006Sue
Sorry the last info was for the site that is working. Here is the info for the site that is not working.
September 8, 2022 at 7:10 am #2337023Sue
You will need to add /blog on the link.
September 8, 2022 at 7:15 am #2337026David
StaffCustomer SupportHi there,
so you have a Block Element with the title and the category list inside.
If you select the top level Container Block, in Advanced > Additional CSS Class(es) add:category-filter
Then you should see the effect
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 8, 2022 at 7:38 am #2337042Sue
Wow, thank you so much.
I’d like to learn more about using CSS with GP, is there somewhere in the documentation that talks about programming with CSS?
Thanks again,
September 8, 2022 at 9:41 am #2337262David
StaffCustomer SupportDo you know much about CSS and HTML ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 8, 2022 at 10:11 am #2337291Sue
I know the basics of both and some JavaScript. I enjoy coding but don’t often have an opportunity to (GP makes styling so easy :-). When I have time in a project to work on something like this in I do. Do you know of any resources for learning more about CSS?
I appreciate you taking the time to ask me the question.
Thank you,
SueSeptember 9, 2022 at 5:37 am #2337915David
StaffCustomer SupportThere are lots of courses when it comes to writing Themes and Plugins, and their associated HTML, CSS and JS. Which is great for levelling up your HTML and CSS skills, but in most instances, like in this topic, the HTML is written by something else ( WordPress core, The Theme, a Plugin ). And that HTML is not visible in the WP Admin.
For that reason my biggest recommendation is to keep on using the Browser Developers Tools to inspect the HTML:
https://developer.chrome.com/docs/devtools/dom/
If we can read the HTML, and we can see its attributes (
class
,id
,href
,data-attr
etc, ) then we can use them to write CSS. I learnt most of what i know from using the developers tools over and over again.Some useful things to know:
WordPress adds a lot of Classes to a lot of the HTML you see.
The two main functions it uses are:i)
body_class
for adding classes to the<body>
tag
ii)post_class
for adding classes topost
elements such as thearticles
in your post loop.The classes it adds are generally very high level descriptor classes. For example on the
body
you will see template classes such assingle-post
orarchive
and on thepost
you may see an ID or acategory-term
.These are all super handy for styling elements based upon those high level rules:
For example:
.single-post a { /* style for my single post links */ }
or
article.category-idea .read-more { /* style the readmore link on posts with the category term idea */ }
Themes and plugins add to the Body and the Post classes
WP provides Filter Hooks:
body_class
andpost_class
that allow developers to add Classes to those elements.
GeneratePress as do other themes and plugins do use them.For example in the
<body>
tag you will see classes likeno-sidebar
orseparate-containers
which are theme added classes that are directly related to your customizer choices.In most instances the classes the theme adds such as
separate-containers
orheader-aligned-left
are constant, as in they are present on every page, post, archive. And the Theme uses them to simply load the styles based on your Customizer options.But some classes like
no-sidebar
vsright-sidebar
can be used to style different posts, pages etc. for layouts you can set on individual posts.Reading CSS Selectors Right to left, and HTML from bottom to top
When we view a CSS selector eg.
.gb-container.category-filter .wp-block-categories-list li.current-cat a
We would read them from left to right. But browser reads them from right to left.
In this instance it checks anya
element, and looks up its parent tree to see if its a child of a<li class="current-cat">
, and if that element is a child of ofwp-block-categories-list
and if that is a child of an element withclass="gb-container category-filter"
See here on the original Geek Site:
Also note in the Styles panel, there were several CSS styles adding
color
to that element, and the Top Most one is the CSS style that got applied because it has much greater specificity.The missing class
In the original issue, the problem as you identified was the missing
category-filter
class.
This had to be manually added to the relevant Block in the editor. But we could also have added it here – in the yellow box:As following the right to left logic and down to up reading, the CSS selector would still have been true.
So why do we add that
category-filter
selector. Simply so that thewp-block-categories-list
will receive our custom CSS if it is inside a gb-container with a specific class. Meaning you can use the Category List Block elsewhere and keep its default styles.Over specification
if we look at this CSS rule, its really over specific:
.gb-container.category-filter .wp-block-categories-list li.current-cat a { color: var(–base-3); }
It could have been:
.category-filter .wp-block-categories-list .current-cat a { color: var(–base-3); }
And that would still work, if you follow the above right to left, bottom to top logic.
But as much as we want to keep code small, the unnecessary class and tags help identify what they do.eg. the
gb-
prefix we use for all our GenerateBlocks auto generated classes. Sogb-container.category-filter
shows we have an Additional CSS class adde to a GB Container BlockLikewise the
li
inli.current-cat
tells us we should look for a list item.So sometimes verbose selectors are very handy 🙂
Does that help ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 9, 2022 at 10:51 am #2338347Sue
This is terrific. Thank you so much!
Sue
September 10, 2022 at 4:03 am #2338763David
StaffCustomer SupportAwesome – glad to be of help!
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.