How to Create Unique Designs Using Before and After Pseudo Elements in Divi

Last Updated on September 17, 2022 by 19 Comments

How to Create Unique Designs Using Before and After Pseudo Elements in Divi
Blog / Divi Resources / How to Create Unique Designs Using Before and After Pseudo Elements in Divi

As web designers we are always looking out for new ways to add individuality to the websites we create. Divi provides endless opportunities to produce unique layouts but there are always little additions we can include to bring a design together. This is where CSS pseudo-elements come in really handy.

What are CSS pseudo-elements?

Put simply, a CSS pseudo-element can be utilised to style specific parts of an element. There are five types of pseudo-element that do different things. For the purpose of this post weโ€™ll be looking at ::before and ::after.

These two pseudo-elements are used to insert something before or after the content of an element. This is particularly useful since we can use them to add extra visual elements to existing images, text and anything else!

So why would we use these pseudo elements? Before and after are perfect for unlocking design possibilities without needing to add more elements or modules. Equally, they are useful for adding additional elements without having to touch html templates or core theme files.

How do you use before and after elements with Divi?

If this all sounds a little confusing so far, do not worry! If we were to use ::before and ::after when writing the CSS code from scratch, it would look a little like this:

Imagine we have a line of text with the class โ€œtext-exampleโ€ โ€“ the CSS to style and customise this line would be:

.text-example {*This is where you add the styles*}

Now if you wanted to add and style a ::before or ::after element, the CSS would look like this:

.text-example::before {*This is where you add before content and styles*}
.text-example::after {*This is where you add after content and styles*}

Fortunately Divi provides easy access to ::before and ::after pseudo-elements with much less hassle. In fact, if you have ever opened up the โ€œAdvancedโ€ tab for any module to add custom CSS code, youโ€™ll have seen the areas that we are referring to.

These boxes provide a quick shortcut to add and customise content before and after any existing Divi module and we can utilise them to create some really flexible and interesting designs.

Sneak Peek

This is what weโ€™ll be creating in this tutorial:

Example 1

Example 2

Example 3

Getting Started

For this tutorial we just need a copy of the Divi theme and a blank slate. To begin with weโ€™ll create a new page and, after adding a page title, click on the visual builder.

Now weโ€™re ready to begin!

Example 1: Numbered blurb modules using Pseudo Elements

The blurb is probably one of the most flexible Divi modules at your disposal. In this instance we will use pseudo elements to add numbers before each blurb to create a step by step โ€œhow it worksโ€ section. Weโ€™ll also add an arrow shape to the right to indicate the process.

What weโ€™ll be creating:

Although this design will work with any blurb design, weโ€™ve borrowed the blurb section from the Web Agency Layout. If youโ€™d like to use these as a starting point you can access the Web Agency Landing Page by creating a new page and accessing the front end builder.

When your page loads youโ€™ll have an option to use a premade layout, one of your saved layouts or build from scratch. Select premade layout and use the search bar to find โ€œWeb Agencyโ€ Layouts. The blurb section in this tutorial can be found on the Landing Page.

Once loaded, the only difference between the premade layout and our example is that weโ€™ve changed the background of each blurb, the title and text font colour and added a little padding.

Once youโ€™ve changed these settings on one blurb, you can right click on the module and use the โ€œExtend Stylesโ€ to apply them to the other three.

Now that weโ€™ve customised our four blurb modules to look as we want them, itโ€™s time to add some code to create the numbered element. However for this design to work we first need to add one line of css to the Main Element custom css box.

overflow: visible;

This will simply allow any elements we create in the next steps to be visible wherever they overlap the edges of our blurb module.

Once youโ€™ve done this, open up the module options and navigate to the โ€œAdvanced Tabโ€. Within the โ€œbeforeโ€ box, add this CSS snippet:

content: '1.'; /* Adds the number 1. as before content */
font-weight: bold;
font-size: 80px;
opacity: 0.7; /* Makes the number slightly transparent */
color: blue; /* Changes the color of the number text */
position: absolute; 
z-index: 9999;
left: 0; /* Positions the content 0px away from the left border */
Top:-20px; /* Positions the content 20px above the top border */

Once you have added this code snippet youโ€™ll see the number appear to the top left of the blurb module. You can amend the numberโ€™s position by altering the โ€œleft:โ€ and โ€œtop:โ€ lines or change the color and font size of the number within this CSS snippet.

Once youโ€™ve completed this for the first module, go into the three new blurb modules and change the โ€œcontent:โ€ line to:

content: โ€˜2.โ€™;
content: โ€˜3.โ€™;

โ€ฆand so on.

Now that weโ€™ve got our numbers sorted, we need to add a little bit of css to create the arrow shape.

Open each module and enter this into the After box within the Custom CSS area:

content: '';
display:block;
height:60px; /* Size of the shape */
width:60px; /* Size of the shape */
position:absolute;
top:40%;
right:-30px;
z-index: -1;
background-color: #e8e8e8; /* Colour of the shape */
transform: rotate(45deg);
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);

Now your four blurbs should look like this:

Example 2. Adding unique shapes to your existing modules

This design relies on simple but effective little code snippets that are added to both the ::before and ::after custom CSS boxes within each text module.

The beauty of using pseudo-elements here is that we can integrate unique shapes and objects to our existing modules without needing to add any additional elements or modules to our page. Because these pseudo-elements are contained within our existing modules, they donโ€™t add any extra space to our designs and remain looking great on all devices.

What weโ€™ll be creating:

To create the initial layout we need to add a regular section with a three column row, set to default width. Once youโ€™ve done this, add a text module to one of the new columns.

Again, you can style this text module as youโ€™d like however if you are following along, these are the steps to achieve this design:

Open the text module options and add your text content and a background image or background colour as required. Weโ€™ve used a normal background image with a transparent gradient on top:

Next, configure the following design options:

1.Top padding: 120px & Bottom padding: 120px

2.Text Alignment: center & Text color: #ffffff

3. Heading Alignment: center & Heading color: #f5ee5d

Now that we have all of the visual aspects in place for your first text module, it is time to add the CSS to make the magic happen. In the Advanced tab of the text module, add the following code to the โ€œbeforeโ€ box:

content:'';
height: 30px; /* change the size to suit your design */
width: 30px; /* change the size to suit your design */
display: block;
position: absolute;
border-top: solid 3px #f5ee5d; /* change the colour to suit your design */
border-left: solid 3px #f5ee5d; /* change the colour to suit your design */
left: 20px; /* change the position to suit your design */
top: 20px; /* change the position to suit your design */

And then add the following code to the โ€œafterโ€ box:

content:'';
height: 30px; /* change the size to suit your design */
width: 30px; /* change the size to suit your design */
display: block;
position: absolute;
border-bottom: solid 3px #f5ee5d; /* change the colour to suit your design */
border-right: solid 3px #f5ee5d; /* change the colour to suit your design */
right: 20px; /* change the position to suit your design */
bottom: 20px; /* change the position to suit your design */

Once youโ€™ve added these code snippets to the module you will see our fancy new shapes added.

If you wondering what this CSS does, itโ€™s actually quite simple. All we are doing is creating a transparent square that is positioned 20px away from the top and left (and bottom and right) of the text module. We then add two borders to these squares to create the arrow effect.

When youโ€™re happy with the look of this first text module, simply copy and paste it to fill the other columns and change the text content, background and styles to suit.

The bonus of this method is that it will work with pretty much any Divi module with a little customisation. If you want to be more fancy, try adding some additional CSS to rotate, skew and customise the ::before and ::after elements even further. Have fun!

Example 3. Adding icons and descriptions to tab titles

Within this design we will take advantage of the ability to add an image icon before some existing content as well as a small text description below. This is perfect for customising the Divi tabs module a little further than you are normally able to.

Note โ€“ Although adding content via css is great for design, it isnโ€™t readily indexed by search engines (although Google does in fact index CSS and Javascript content, it takes much longer and is unreliable at present. Search engines like Bing and DuckDuckGo do not index this content at all). For this reason your content should be minimal and you should not rely on it to influence your ranking potential.

What weโ€™ll be creating:

First of all we need to add our standard section and a 1 column row, followed by the Divi tabs module itself. Within the tabs module, we only need to add our titles and content to each tab as weโ€™ll be handling the styles in the next steps.

Once our content is in place, we need to begin adding content to the ::before element of the module. Since we cannot add custom CSS to specific tabs using the method weโ€™ve followed above, weโ€™ll need to accomplish this slightly differently.

Open up the tabs module options and within the Advanced tab give the module the class โ€œfancy-tabsโ€.

Once youโ€™ve added this CSS class we need to do a little preparation. To add some icons or images to your tab titles we obviously need to add these to WordPress. Go to the Media tab in the WordPress dashboard and upload your chosen icons as you normally would.

With your images uploaded, we need to click on each one and copy the URL that WordPress has generated for us. Go through each of your images and copy and paste these URLs into a document or your chosen notes application.

With the URLโ€™s of your chosen images at hand, go to your Divi Theme Options within the Divi menu in the WordPress Dashboard.

At the bottom of this page youโ€™ll see a box where you can add your own custom CSS. Itโ€™s within this box that weโ€™ll be pasting some CSS code.

The following snippet will add the images above each tab title. Simply copy and paste this snippet into the custom CSS box and replace the content between (and including) the asterisks (e.g. *Replace this with the URL for your first image*) with the URLs you noted earlier.

.fancy-tabs .et_pb_tab_0 a::before {
content: url(*Replace this with the URL for your first image*);
padding-top: 20px;
display: block;
}

.fancy-tabs .et_pb_tab_1 a::before {
content: url(*Replace this with the URL for your second image*);
padding-top: 20px;
display: block;
}
 
.fancy-tabs .et_pb_tab_content a::before {
content: '' !important; }

If you return to the page with your tabs module on, you should now see that the images have been added above each title โ€“ success!

So what about adding descriptions? Fortunately this is quite simple as well. Right below the code you have just copied into your custom CSS box, paste the following:

.fancy-tabs .et_pb_tab_0 a::after {
content: 'this is a description';
font-size: 10px;
padding-top: 5px;
display: block;
}
 
.fancy-tabs .et_pb_tab_1 a::after {
content: 'this is a description';
font-size: 10px;
padding-top: 5px;
display: block;
}
 
.fancy-tabs .et_pb_tab_content a::after {
content: '' !important; }

As before with your images, youโ€™ll need to replace โ€œthis is a descriptionโ€ with your own content. Returning to the page with your tabs module on youโ€™ll see we now have fancy descriptions too!

Finally, we just have to apply a little more CSS to achieve the complete design shown above. Again, copy the following snippet into the same custom CSS box:

.fancy-tabs .et_pb_tab_content a:after {
content: '' !important; }

.fancy-tabs .et_pb_tabs_controls li {
width: 50% !important;
}
.fancy-tabs .et_pb_tabs_controls li a {
width: 100% !important;
text-align: center;
}

@media (max-width: 768px) {

.fancy-tabs .et_pb_tabs_controls li {
width: 100% !important;
}

.fancy-tabs .et_pb_tabs_controls {
padding: 0 !important;
}
}

This code centers your tab text and images and increases the width of your tabs to cover the entire module.

We also added some CSS to ensure the tabs look good on all devices โ€“ if youโ€™d prefer to not have your tabs full width and stack on mobile, weโ€™ll need to go back and surround the original CSS code in a media query. This means that on devices the size of a tablet and wider we add the descriptions and icons, however on smaller devices we will revert back to the Divi default styling.

To do this, copy the amended CSS code below and paste it into your custom CSS area in the Divi theme options panel:

@media (min-width: 769px) {

.fancy-tabs .et_pb_tab_0 a::before {
content: url(*Replace this with the URL for your first image*);
padding-top: 20px;
display: block;
}

.fancy-tabs .et_pb_tab_1 a::before {
content: url(*Replace this with the URL for your second image*);
padding-top: 20px;
display: block;
}
 
.fancy-tabs .et_pb_tab_content a::before {
content: '' !important; }

.fancy-tabs .et_pb_tab_0 a::after {
content: 'this is a description';
font-size: 10px;
padding-top: 5px;
display: block;
}
 
.fancy-tabs .et_pb_tab_1 a::after {
content: 'this is a description';
font-size: 10px;
padding-top: 5px;
display: block;
}
 
.fancy-tabs .et_pb_tab_content a::after {
content: '' !important; }
.fancy-tabs .et_pb_tab_content a:after {
content: '' !important; }

.fancy-tabs .et_pb_tabs_controls li {
width: 50% !important;
}
.fancy-tabs .et_pb_tabs_controls li a {
width: 100% !important;
text-align: center;
}
}

Adding more tabs

In this instance we have created a tab module that includes 2 different tabs, however in practice we sometimes require more than this. If you are in a position whereby you are seeking to create more than 2 tabs, we will need to amend the code youโ€™ve just added.

As you can see from the snippet, Divi automatically assigns a class to each tab title โ€“ the first starting with 0 (.et_pb_tab_0), increasing by 1 each time (.et_pb_tab_1, .et_pb_tab_2 and so on). Weโ€™ve already taken care of the first two tabs, so when adding more we can simply copy and paste a section of the code for every new tab:

.fancy-tabs .et_pb_tab_0 a:before {
content: url(*Replace this with the URL for your first image*);
padding-top: 20px;
}

and change the number in the class (.et_pb_tab_0) to 2, 3, 4 etc. Youโ€™ll need to do the same for your descriptions too.

The final amendment we need to make is to adjust one more line of CSS. Take the number of your tabs and divide it by 100. Note down this number and navigate to the following section in your custom CSS:

.fancy-tabs .et_pb_tabs_controls li {
width: 50% !important;
}

and swap the 50% with your answer. This will ensure your tabs are equally spaced across the width of the module.

For example, if you are creating a third tab, the additional CSS code you need would be as follows:

.fancy-tabs .et_pb_tabs_controls li {
width: 33% !important;
}

In closing

And there we have it, three great ways to utilise CSS ::before and ::after elements to create new design possibilities. Hopefully this guide will inspire you to explore how you can use pseudo-elements in your future creations โ€“ the opportunities really are endless!

Divi Marketplace

Are You A Divi User? Find Out How To Get More From Divi! ๐Ÿ‘‡

Browse hundreds of modules and thousands of layouts.

Visit Marketplace
Divi Marketplace
Divi Cloud

Find Out How To Improve Your Divi Workflow ๐Ÿ‘‡

Learn about the new way to manage your Divi assets.

Get Divi Cloud
Divi Cloud
Divi Hosting

Want To Speed Up Your Divi Website? Find Out How ๐Ÿ‘‡

Get fast WordPress hosting optimized for Divi.

Speed Up Divi
Divi Hosting
Premade Layouts

Check Out These Related Posts

Get a Free Butcher Shop Layout Pack for Divi

Get a Free Butcher Shop Layout Pack for Divi

Posted on April 15, 2024 in Divi Resources

Hey Divi Nation! Thanks for joining us for the next installment of our weekly Divi Design Initiative; where each week, we give away a brand new Layout Pack for Divi. This time around, the design team has created a beautiful Butcher Shop Layout Pack thatโ€™ll help you get your next Butcher Shop...

View Full Post

19 Comments

    • Have you tried using a {color:#ffffff !important;}?

  1. the text I put in ::before is cut off, why does this happen?

    • Have you tried defining a CSS width property on the before pseudo?

  2. Great Article, just used it and it works! Thank you

  3. Excellent tutorial and well supported documentation. Great job and I see more tips and tricks coming from Liam I am sure ๐Ÿ™‚

  4. Liam, Thanks for the useful information. This is another reason to use Divi to builder to create websites.

  5. Excellent tutorial. I will be using some of these top-tips in my next project.

    Kind regards,
    Neil.

  6. Hi Liam, I’m using example 3 and everything works fine whilst I’m using the internal Divi stylesheet. But when I move the code into my Divi-child style sheet it stops working, any ideas?

  7. Wow.. nice article. you have done a really brilliant job. i was really not familiar with the option of “Extend Stylesโ€

  8. The css code is a pending issue. Thanks Liam interesting post.

  9. Thanks Liam, this is great!

  10. One of the tutorials I’ve seen on the pseudo ::before and ::after selectors! Great job Liam, hope you can write more of these advanced CSS topics in the near future!

  11. Great article.

    Thank you.

  12. you blog is very help full

  13. Hello,
    Thank you for this tutorial.
    The tab part is really very interesting.

  14. Thanks it’s very beautiful effects

  15. Thanks a lot man you really help me.I don’t even no some settings that you shown us.

  16. Nice work, thanks ๐Ÿ™‚

Leave A Reply

Comments are reviewed and must adhere to our comments policy.

Join To Download Today