Adjusting the width of the after selector in real-time

I have been working on creating a tab-like feature using CSS for my project.

Currently, when a tab is active, I adjust the CSS of the selected tab using the tab-slider--tabs:after selector. However, I encountered an issue where one of the tab header texts is longer than the others, resulting in a layout problem like this:

https://i.sstatic.net/CiowW.png

I am trying to figure out how to dynamically set the width so that it appears like this:

https://i.sstatic.net/v49cv.png

 .tab-slider--tabs {
  display: block;
  float: left;
  margin: 0;
  padding: 0;
  list-style: none;
  position: relative;
  border-radius: 35px;
  overflow: hidden;
  background: #fff;
  height: 35px;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.tab-slider--tabs:after {
  content: "";
  width: 50%;
  background: #345F90;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transition: all 250ms ease-in-out;
  border-radius: 35px;
}
.tab-slider--tabs.slide:after {
  left: 50%;
}

Check out the: Demo Code

Update: For now, I managed to temporarily solve this issue by using .tab-slider--trigger{ width:30%; display: table-cell; ...}, but I am still seeking a better solution.

Answer №1

Here is a suggestion to consider:

.tab-slider--trigger {
  width:150px;
  font-size: 12px;
  line-height: 1;
  font-weight: bold;
  color: #345F90;
  text-transform: uppercase;
  text-align: center;
  padding: 11px 20px;
  position: relative;
  z-index: 2;
  cursor: pointer;
  display: inline-block;
  transition: color 250ms ease-in-out;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Struggling with coding an array of images in Angular JS

I am having trouble displaying the images as thumbnails and full images for each "gem." The Angular tutorial I followed did not provide enough detail on how to do this. Here is my HTML code: <!DOCTYPE html> <html ng-app="store"> <head> ...

Creating an AI adversary for a simple Tic Tac Toe game board: a step-by-step guide

Being new to programming, I recently completed a basic Tic Tac Toe gameboard successfully. However, as I progress to the next phase of my assignment which involves implementing an AI opponent, I encountered several challenges. As a novice in programming, ...

Creating an element in react-draggable with two sides bound and two sides open - here's how!

At the moment, I am facing an issue where the element is restricted from moving outside of the container with the class of card-width-height. My goal is to have the right and bottom sides bounded within the container while allowing the element to move beyo ...

Utilize the identical mathematical equation across various jQuery values

I have a JavaScript code that calculates the size of circles on the screen based on multiple variables. Currently, I am repeating the same equation for each circle by numbering all the variables accordingly. Is there a way to simplify this process and run ...

triangular shape at the top and rounded shape at the bottom combined with various colors

Is there a way to create a triangle with a rounded bottom section in a different color? #box { content:""; width: 0; height: 0; border-style: solid; border-width: 0 150px 150px 150px; border-color: transparent yellow red blue; ...

Functionality of local data storage

I'm currently exploring the capabilities of the localStorage feature. Let's say I have a large JSON object stored using localStorage. I need to share this data with the testing team for review. However, if I try to display the stored data on an H ...

Ways to position a container div below a menu through CSS

I'm having trouble getting the container div to display below the menu instead of alongside the header. Can someone help me fix this issue? Here is my HTML and CSS code: <!DOCTYPE html> <head> <meta charset="utf-8" /> <title>R ...

The JQuery clone method is failing to generate a new table row

I have a table with a button that is supposed to add a new row dynamically when clicked. However, the functionality is not working as expected. The HTML and JQuery code can be found in this JSFiddle link. Any suggestions on how to fix this issue would be ...

The functionality of $(window).load() varies between Internet Explorer and Firefox

While experimenting with $(window).load() function, I encountered a problem. The function is supposed to wait for the window to fully load before executing any code written inside it. This works correctly in IE, but not in Firefox. In Firefox, it behaves m ...

Joomla, Enhancement for iFrame Sizing

A close associate who runs his own construction business has asked me to create a website for him using Joomla. I have successfully implemented most of the features he wanted, but now I need some assistance. He wants to showcase references written about hi ...

Guide to making a dynamic image map with interactive links using HTML and CSS

Seeking advice on how to create clickable areas within an image that lead to different pages on my website. Image maps seem like a good solution, but the issue is that they require specific coordinates which may not work well for responsiveness. I was hop ...

ThreeJS | The object's position cannot be cloned as it seems to be undefined, however, this is unexpected

My code problem is not as complex as it seems. The issue lies within the section marked by the "ERROR APPEARS HERE" comments. The error message I am encountering reads: Uncaught TypeError: Cannot read property 'position' of undefined This er ...

Tips on choosing a button and applying custom styles with emotion styles in MUI

Looking to apply a margin-right to my button. Currently utilizing mui 5 with Button variant='contained'. I created a custom CSS style using the styled component in mui and targeted the Box. const Wrapper = styled(Box)({ display: 'flex&ap ...

Obtain Data for Visualizing Graph with JSON within a Database-connected Graph (highchart.js)

In the process of creating a database-driven graph, I am utilizing libraries from Codepen. These libraries include: THIS and Highchart.js The HTML file on display simply showcases the chart, while the main data processing is handled in an index.js file t ...

Failure to Establish a Session

I'm encountering an issue where the session remains empty despite having the following code in place. Could someone assist me in troubleshooting this problem? <?php session_start(); ob_start(); $ifLogged = $_SESSION["mbse"]; if(!isset($ifLogg ...

Avoiding caching on HTML pages rendered by the SharePoint content editor web part

Is there a way to prevent caching on a HTML file displayed in a SharePoint library using a content editor web part? I attempted the following methods in the HTML file, but they were unsuccessful: <meta http-equiv="Cache-Control" content="no-cache" /&g ...

How can I use JavaScript to show a div upon clicking an input element?

I am looking to make a block div visible when an input field is clicked. <input class="indifferent" type="radio" name="decision" value="indifferent"> Indifferent </br> <div class="input" style="display: none;"> Please assist with our com ...

attribute alternativeType

<input type="text" name="date" value="" data-type="datetime" required="true" /> I'm looking for a different approach than using dojoType for a couple of reasons: The parseonload behavior causes the page to "jump" when loading (system-defaul ...

Why does Internet Explorer display .png images in lower quality compared to other browsers?

My menu displays a .png file with smooth edges in most browsers, but in Internet Explorer it appears with rough edges. Can someone help me understand why IE treats .png files differently compared to other browsers? <li> <a href="" onclick=" ...

The impact of a water droplet image on the reaction

Hello everyone, I am seeking assistance regarding CSS as the chatroom dedicated to CSS is currently empty. I am attempting to create a water drop effect but haven't had much success so far. Could someone guide me in the right direction? I have tried u ...