Support

Home Forums Event Espresso Premium Proper syntax for custom CSS

Proper syntax for custom CSS

Posted: December 16, 2020 at 9:36 pm


laurieklein

December 16, 2020 at 9:36 pm

I am very new to CSS and trying to customize the look of the button on the single event page using custom CSS. When I put the CSS in my child (parent is Divi) theme’s style.css file, it doesn’t have any impact on the event page’s button. I know it isn’t a problem with the child theme or file, because other customizations in the file work fine on the non EE4 pages. I am thinking I must not be following the proper syntax to reference the page and button. Below is what I have now. Would someone please help me figure out what I am doing wrong?

Thanks in advance for the help.
Shelley

.single-espresso_events .ticket-selector-submit-btn {
background-color: #474747
border-radius: 5px;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}


Tony

  • Support Staff

December 17, 2020 at 7:00 am

Hi Shelley,

The syntax above is correct and it looks like it is applying on the page when I view it:

https://monosnap.com/file/haAFMvxzlj1Rt4tIHLnIzD9TFNFg1a

Have you already figured this out or do you see something different?


laurieklein

December 17, 2020 at 7:17 am

Hi Tony,

Since it worked for you, I tried a different approach. I put the CSS in the Additional CSS block under Appearance rather than in the child theme, and it works there. I guess there is some sort of conflict between the Divi child theme and the EE4 page.

Thanks for verifying the syntax.

Thanks,
Shelley


Tony

  • Support Staff

December 17, 2020 at 7:48 am

There shouldn’t be any conflict when using a child theme, it’s just another style sheet to load.

I can check into that if you switch it back to using the child theme?


laurieklein

December 17, 2020 at 8:30 am

Moved the CSS from the Additional CSS block to the child theme, and it is working now. Obviously, user error yesterday.

Thanks again.


Tony

  • Support Staff

December 17, 2020 at 9:40 am

You’re most welcome, it could also be some caching on the server meaning your browser still had the ‘original’ version and used that.

In any case, I’m glad it’s now working 🙂


laurieklein

December 17, 2020 at 5:05 pm

Another syntax question, please. I am now working on an event listing page. I am creating the page in Divi using the shortcode: [ESPRESSO_EVENTS]. I want to format the buttons the same way I did the single event button earlier in this message thread. I tried the following:

.espresso_events .ticket-selector-submit-btn {
background-color: #474747
border-radius: 5px;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}

It had no impact, so I assume I have a mistake in the initial reference “.espresso_events .ticket-selector-submit-btn.” Is my assumption correct? If yes, what should it be?

I will no doubt need to make other similar adjustments on other pages created with shortcodes. Is there a reference article somewhere to tell me what the appropriate specifiers should be for each?


Tony

  • Support Staff

December 18, 2020 at 7:27 am

It had no impact, so I assume I have a mistake in the initial reference “.espresso_events .ticket-selector-submit-btn.” Is my assumption correct? If yes, what should it be?

It depends on the theme, EE events are output as posts by your theme so the classes are often determined by the theme itself.

Can you post a link to the page in question so I can take a look?

I will no doubt need to make other similar adjustments on other pages created with shortcodes. Is there a reference article somewhere to tell me what the appropriate specifiers should be for each?

Not currently, mainly because of the above.

I find the best way to find the correct classes/IDs on the page is to use Chrome Dev Tools to view the elements and work back from there.

If you can link me to the above page I’ll show you how I would work through to find the correct selectors from there.


laurieklein

December 18, 2020 at 8:52 am

Thanks, Tony. A walkthrough of your process for determining the correct selectors would be incredibly helpful. The page I am trying to make the button modifications on is here: https://ljk.vandegriftphotography.com/ljk_dev/workshops-events-listing/. I want to make any buttons appearing on the page match the styling of other pages on our site.

I feel pretty good about working with CSS, but I am really struggling with how to determine the correct selectors. I use the Inspect tool in Chrome to attempt to find the selectors, but I am obviously missing something. This is the first time I have tried to figure this out on plugin posts and pages.

Thanks,
Shelley


Tony

  • Support Staff

December 18, 2020 at 9:28 am

That selector is correct, it’s working for me?

I copied your styles into Chrome and it shows they apply:

https://monosnap.com/file/AJMM1aqAQ2Ho5pugACmJLSUUX984jd

What steps are you taking to test this? Based on this and your other thread I suspect there’s some form of Caching going on.


laurieklein

December 18, 2020 at 9:40 am

Tony that is very odd. I have purged the caching and still do not get the correct result.

What I am doing is this:

-Using Chrome Inspect, try to figure out what the correct selector is (Would still really love to know your process for finding these)
-Write the custom CSS using the selectors identified and add it to my child theme’s style.css
-Ftp the file to my child theme folder for the site
-Go back to the page and reload it by right click>reload
-Check how the item appears on the page to see if it shows the change

I just went in and cleared the cache then opened the page, and I still see the original, “out of the box” button styling. Can’t for the life of me figure out why you see it modified and I don’t.


Tony

  • Support Staff

December 18, 2020 at 2:33 pm

I don’t see it modified by default, I’m applying your styles in Chome Dev tools to confirm they work, which they do, but when I load the page I don’t see that styling.

Ok, first, a quick guide on Chrome Dev Tools. Or a least how I use Chrome Dev Tools to find the selector I need.

So you want to target the Ticket Selector button, right-click on it and do inspect.

That will open Chrome Dev Tools on the inspect tab and select the element you are inspecting. Like this:

https://monosnap.com/file/Djr4NEfKBH3jXtu7p1YjWPyoaV0yAN

Do know the difference between ID’s and classes?

ID’s use # and classes use ., an ID should only be used once on a page where as classes can be used multiple times.

So knowing that we can look at the button input itself, if we use the ID it’s only going to target THAT specific button, but it has a class of ticket-selector-submit-btn meaning all those buttons will have that class and all can be targets using it.

So start with:

.ticket-selector-submit-btn {
    // Styles here
}

Now working up through the ‘parent’ elements allows us to get a little more specific on where those styles apply, so let’s use your example:

.espresso_events .ticket-selector-submit-btn {
    // Styles
}

Work right to left and that says any element with class ticket-selector-submit-btn that is within an element espresso_events.

Looking at our inspector again: https://monosnap.com/file/jhgio9iYFfdoN9k5CGPUWN6dGlVdB1

Which means your selector is fine and will target that button, your specifically targeting that button within an element that has a class of espresso_events but in this case thats fine. The point is that your getting more specific with your styling now because your dialling in on specific parent/child relationships etc.

Now, on your site your CHild theme’s CSS is currently using this selector:

.single-espresso_events .ticket-selector-submit-btn {
    // Styles
}

Now you have a bit of a problem here as that’s specific targeting SINGLE espresso_events posts and an event list is NOT a single event post, its multiple. Notice in our inspector we do NOT have that single-espresso_events class on that page? That style doesn’t apply there, it will only apply on a page like this:

https://ljk.vandegriftphotography.com/ljk_dev/events/infrared-a-to-z/

(When you’ve clicked through to the event)

Use inspector again and you’ll see that class is on the above page, but you’ll also see is has an article element with class .espresso_events just like the other. So, switching the above style back to what you posted earlier means it targets both of those pages.

The above gets a little easier the more you do it, you start to notice classes that can be used on all the various sections you want to target and pick up how you can use the same class for multiple outputs, there isn’t really a shortcut to learning how to do that other than walking through it.

May I ask why you switched to use .single-espresso_events?


laurieklein

December 18, 2020 at 3:19 pm

I do know the basics of IDs and classes, but thanks for the refresher.

When I added the shortcode to the page, I used this:

[ESPRESSO_EVENTS css_class=”my-events-class”, show_title=false]

So when I wrote the custom CSS, I wrote this:

.my-events-class .view-details-btn {
background-color: #474747;
border-radius: 15px;
color: white;
padding: 15px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
}

Earlier in the same child CSS I have a section to restyle the button on the single espresso event file which reads as follows:

.single-espresso_events
.ticket-selector-submit-btn {
background-color: #474747;
border-radius: 15px;
color: white;
padding: 15px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 14px;
}

If I am understanding, you are saying I could just use .ticket-selector-submit-btn and it would apply to that button regardless of where it appears. I just tried that after clearing the cache and it doesn’t seem to be impacting any of the places this button appears.

This is so frustrating. Just can’t figure out why this isn’t working.


Tony

  • Support Staff

December 18, 2020 at 3:40 pm

[ESPRESSO_EVENTS css_class=”my-events-class”, show_title=false]

Don’t use quotes in the shortodes unless you have spaces in the attribute, my-events-class does not, also the comma is invalid.

Each attribute is separated by a space, so that should be:

[ESPRESSO_EVENTS css_class=my-events-class show_title=false]

Although personally, I wouldn’t use the additional css_class there.

Where are you adding this additional code/changes?

Your child theme style have not changed:

https://ljk.vandegriftphotography.com/ljk_dev/wp-content/themes/LJKDiviChild/style.css?ver=4.7.7


laurieklein

December 18, 2020 at 3:46 pm

I am making all changes in the child CSS. If you notice on the link you provided, (https://ljk.vandegriftphotography.com/ljk_dev/wp-content/themes/LJKDiviChild/style.css?ver=4.7.7 ) I commented out the single-espresso_events to try just specifying the ticket-selector-submit-btn. Didn’t make any difference.


laurieklein

December 18, 2020 at 3:49 pm

Found a workaround. I put the CSS in the Additional CSS section on the site rather than in a child theme. That worked. Who knows why the Child theme isn’t working. Oh well, the path of least resistance….


Tony

  • Support Staff

December 21, 2020 at 7:24 am

Odd, but I’m glad you found a working solution.

The support post ‘Proper syntax for custom CSS’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso