Horizontal tab titles on mobile in CSS and Elementor

In this tutorial, you will learn how to make horizontal tab titles on mobile and make them stick on top of your tab section using Elementor Pro and CSS.

This is the end result we will be getting on mobile view:

Keep reading or watch the video below!

I am using Elementor Pro version that enables me to directly put my CSS code in the widget section.

If you are using Elementor FREE version, you can use one of the free plugins to put your CSS code there. Like this Simple Custom CSS and JS plugin.

Now let’s see how to make our tab titles horizontal on mobile!

Start by placing the ‘Tab’ widget

Use a ‘tab’ widget and place it on your Elementor page.

Add as many tab items as you need. In this example, I am using 5 of them. Add their titles and some content to each of them. I won’t go too much into details on how to style the ‘tab’ widget. For now, I will just set the ‘Alignment’ to center in the ‘Content’ tab and remove the border in the ‘Style’ tab.

Switch over to mobile view

Since we are adjusting our tab for mobile view, switch over to mobile (responsive) view in Elementor. This way we can see what we are doing and how it looks like directly on mobile size. You can see that by default, the tab items are listed in a vertical view with tab titles being in a sort of a vertical list. When we click on a desired tab title to expand the tab item, you can see that the result is not what we want to achieve.

Let’s see how to keep these tab titles on top of our tab element and put the tab titles in horizontal, not vertical view.

Add the CSS code

Now is the time to add the CSS code to our tab widget. I am using Elementor Pro, so all I need to do to add CSS is head over to my ‘Advanced’ tab and scroll down to the ‘Custom CSS’ field.

I will start by adding the following code:

selector .elementor-tabs-wrapper {
display: flex;
}

Let me explain what this code does. We are using ‘selector’ since we are typing our CSS directly in the Elementor widget. This way we are telling Elementor to apply our CSS code to that ‘selected’ widget. Then, we will call out the class .elementor-tabs-wrapper and set display to ‘flex’ in order to place our titles next to each other.

Now, don’t worry about having two tab lists at this moment. We will get rid of the second one in a minute.

Let’s see how to fix our tab title list going out of the screen. Currently, we can see only the first tab item titles showing in our horizontal list on top, while the remaining ones are going out of the screen.

Add the following code:

flex-wrap: wrap;

I will now use a little bit of styling to center my titles on the screen:

justify-content: center;
-webkit-box-pack: center;
list-style: none;

Our final code for now will look like this:

selector .elementor-tabs-wrapper {
display: flex;
flex-wrap: wrap;
justify-content: center;
-webkit-box-pack: center;
list-style: none;
}

Now let’s get rid of the second vertical tab list that we don’t actually need. In order to do that, I should explain that that second vertical tab elements are actually Elementor tab titles for MOBILE. They have a special class assigned automatically in Elementor, so all we need to do is hide that title class.

We will use this code:

selector .elementor-tab-mobile-title{
    display: none;
}

Styling the tab title colors

Now let’s move on to style our tab titles. In order to do that, we will be adding our code to the DESKTOP version of our tab titles. That styling will then apply to both desktop AND mobile view. (Remember that we are not using the ‘mobile’ tab titles that are currently hidden, only the desktop ones are visible)

Let’s make the default color for our titles black:

selector .elementor-tab-desktop-title a{
    color: black !important;
}

Then, I want to edit the hover state of these tab titles. I will make them with lower opacity on hover.

selector .elementor-tab-desktop-title a:hover{
    opacity: 0.5;
}

Next, I will edit the ‘active’ state of my tab titles. This will determine the color (or any other text attribute) of the currently active tab title, once we click on the corresponding tab item.

selector .elementor-tab-desktop-title.elementor-active a{
    color: red !important;
    opacity: 1;
}

Note that I like to also set the opacity in the active tab title state, since we modified the opacity for the hover state of this element. This way I am making sure that the opacity for my active state doesn’t get overridden by previously defined hover state.

Finally, I will adjust the padding around my titles a bit to reduce the spacing. For that, I will use the following code:

selector .elementor-tab-desktop-title{
    padding-top: 10px;
    padding-bottom: 10px;
}

And that’s it! We have successfully made our tab titles horizontal on mobile and we made them stick on top of our tab elements using these few lines of CSS code.

This is how our final CSS code looks like:

selector .elementor-tabs-wrapper {
display: flex;
flex-wrap: wrap;
justify-content: center;
-webkit-box-pack: center;
list-style: none;
}

selector .elementor-tab-mobile-title{
    display: none;
}

selector .elementor-tab-desktop-title a{
    color: black !important;
}

selector .elementor-tab-desktop-title a:hover{
    opacity: 0.5;
}

selector .elementor-tab-desktop-title.elementor-active a{
    color: red !important;
    opacity: 1;
}

selector .elementor-tab-desktop-title{
    padding-top: 10px;
    padding-bottom: 10px;
}

Download Elementor Pro here.

*This post may contain affiliate links. If you click on a link and make a purchase, I will receive a commission from the sale, with no extra cost to you. That way you are supporting my blog and allowing me to keep making videos and posts like this. I only promote products that I use, have experience with and support, such as Elementor Pro.

Share this post:

Leave a Comment

Related posts:

General instructions:

  1. Open the exercise in your browser and read the task and the content on the left side of the screen. 
  2. You will be editing the content on the right side of the screen.
  3. In order to do that, right click on the exercise page that you opened and go to ‘Inspect’.
  4. Go to ‘Sources’ in the top bar and if you cannot see an empty CSS sheet where you can type the code, press Ctrl + P and start typing ‘styl’ in the search bar. Then press enter to open the CSS sheet.
  5. Follow the notes on the left and start typing your CSS code to see the changes online!
  6. Important! Do not refresh the page while you are editing the code, as these changes are in preview mode only and you can see them immediately, as soon as you write a line of functioning code.
  7. Use the custom classes in the notes on the left side of the screen, as well as ‘Elements’ on the top bar of the ‘Inspect’ to target and style the classes and elements. For example, you can enable the small icon on the top left of the ‘Inspect’ window (‘Select an element in the page to inspect it’) to find the default class name of the element you want to edit, while you are in the ‘Elements’ tab.

Tips:

  1. If the code is not showing any changes, try adding the !important tag at the end of the line before closing it (before the “;” symbol) and see if it works then.
  2. Don’t forget there are usually more ways to achieve the same result. Be creative!
  3. If you get stuck, write your email address in the form on the left side of the screen and you will get the solution (CSS code) in your email.

Sources:

  1. You can find a lot of tutorials on my youtube channel. 
  2. Watch the tutorial on how to solve these exercises here.

Please check your email and stay tuned for updates on the course.

We will notify you shortly when it’s available for presale.