What is the best way to implement logic for managing CSS "After" Pseudo-elements?

My current setup includes HTML in Pug and Vue code, functioning smoothly with dynamic arrow width adjustment.

  .abc--step-bar: .abc--step-bar-color(:style="`width: ${progressBar.width}`")
  .row
    .col(v-for="(item, i) in progressItems")
      .abc--step-item(:class="{ 'is__done': progressBar.index > i, 'is__current': progressBar.index === i }")
        span.abc--step-dot        

The accompanying SCSS for styling is as follows:

.abc--step-bar {
  position: absolute;
  top: 0;
  left: 16.7%;
  right: 16.7%;
  height: 3px;
  background: #e8e8e8;      
}

.abc--step-bar-color {
  background: #28A745;
  position: absolute;
  top: 0; bottom: 0; left: 0;
  
  &:after {
    color: #28A745;    
    content: url("../../assets/images/arrow.png");;
    display: inline-block !important;
    width: 0;
    height: 0;        
    position: absolute;
    right: 6px;
    top: -6px;
  }       
}

.abc--step-dot {
  display: inline-block;
  width: 15px;
  border-radius: 50%;
  height: 15px;
  background: #e8e8e8;
  border: 5px solid #e8e8e8;
  position: relative;
  top: -7px;

  .is__done &,
  .is__current & {
    border: 5px solid #28A745;    
    //background: #28A745;
  }
}

An external image is utilized for the arrowhead:

https://i.sstatic.net/8HEwO.png

I am seeking a method in Vuejs to hide the arrowhead based on specific logic, like when progressBar.index equals 1 and the arrow is an after pseudo-element.

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

To demonstrate this concept, I have replicated it in a CodePen:

https://codepen.io/steve-ngai-chee-weng/pen/xxXmRer

Answer №1

Implement a Vue conditional CSS class called hide-arrow to hide it. Remember, JavaScript cannot directly target pseudo elements.

.abc--step-bar-color.hide-arrow::after { content: ""; }

Keep in mind that using :after is an outdated syntax from CSS 2.1. In CSS 3, pseudo elements should be prefixed with ::.

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

Firefox 3.x exhibits a glitch where PNG background images vanish and are unable to load

The issue at hand is as follows: I am facing a problem with a non-floated div (#bottom) that has a fixed height defined in CSS (24px), which used to display its background (bottom.png) until I added content inside. CSS: #bottom {height: 24px; backgroun ...

Troubleshooting issues with VueJS child component routing issues

When attempting to access the child route, it doesn't show up. Instead, it displays a "not found" error. Even when I specify the path in children as /:menuid/page/sample2/child1, it just loads the parent route and renders the data of Sample2. What am ...

Expanding the height of Bootstrap 4 cards

I'm having an issue with Bootstrap 4's card columns where the height of the shorter card ends up stretching to match the one beside it. This only occurs when I add the 'row' class to the parent div. If I remove the 'row' class ...

Is the concept of client-side authentication, similar to that on single-page applications, simply a facade to deter users who trust in it from tampering with the data on the server side?

Is client-side authentication, like on SPAs, simply a ruse to deter users who believe it from attempting to manipulate the data on the backend, which is protected by real authentication? When we develop SPAs with technologies such as Vue, Vue Router, Reac ...

Tips for maintaining consistent content length of nested divs as one div's content grows

I am looking for a solution to ensure that when the map is running on my MUI card, some cards with more text content will increase in length while maintaining equal text alignment. I have attached a screenshot of my actual app and a CodeSandbox example for ...

The erratic appearance of inactive elements within ExtJS components

I am currently working on an ExtJS form that utilizes hbox-layout containers to generate sentences containing various form inputs. There is a specific requirement to disable the form under certain conditions. These hbox-layout containers consist of compone ...

What is the best way to modify CSS and HTML with a post request?

I'm currently in the process of working on a webpage with multiple sections. One section includes a form that sends a POST request. Once this form is successfully submitted, I want to update the CSS style of another element to make it visible. Given ...

Displaying a value in a React component using material-ui's TextField

Can anyone help me with printing the email a user enters into the textfield within the Dialog when a button is clicked? I have been struggling to achieve this due to my function's structure. Any guidance would be greatly appreciated. export default fu ...

Tips for implementing event handlers on dynamically generated li elements in VueJS

Creating multiple ul elements using v-for in the following way <div v-for="item in info"> <ul> <li><a>{{item.number}}</a></li> <li><a>{{item.alphabet}}</a></li> </ul> </div&g ...

The Vue component fails to display the updated data even after the prop data has been modified

This is the parent component called abc.vue <v-card outlined class="mt-4"> <DetailsTable v-show="toggleClientData" :columnDefs="columnDefs" :rowData="rowData" /> </v-card> methods:{ aggridData() { let self = this; th ...

Avoid mutating the prop directly and instead, utilize a data or computed property that is based on the value of the prop. The prop that is being mutated in this case is

Help me understand this issue that Vue is displaying, I am not sure what is going on. This is my progress element: <el-progress :percentage="percentCompleted" v-show="uploadingVideo"></el-progress> data() { return{ percentCompleted: 0 ...

Tips for eliminating repetitiveness in situations such as BEM modifiers

As I delved into using my own adaptation of the BEM methodology, I encountered a roadblock with modifiers for nested elements. The challenge at hand is changing the link color to red when product-desc-name has the mark class. The snippet below illustrat ...

Transmitting form data inputted by the user to a modal that resides in the same component, all without the need for child or parent components or

In need of a solution where users can input answers to questions and have all the entered data displayed in a popup alongside the respective question. If a user chooses not to answer a question, I do not want that question or any related information to be ...

Troubleshooting the Missing Border Issue in Tailwind Form Fieldset [Code Snippet Included]

I am developing a basic react application with the help of Tailwind css. Scenario 1: Functioning correctly without tailwind: https://codesandbox.io/s/bold-agnesi-y70ue In this example, the tailwind library is not utilized. The simple react app displays ...

Having trouble loading the image source using JSON in Vue.js

var topArticle=new Vue({ el:'#toparticle', data:{topmostArticle:null}, created: function(){ fetch('topnews.json') .then(r=>r.json()) .then(res=>{this.topmostArticle=$.grep(res,functi ...

Issues with reactivity are present in certain items within Vue.js cards

Can someone please assist me with this issue that has been causing me trouble for days? I am working on updating the quantity and total price in a checkout card: The parent component: <template> <div> <upsell-checkout-product ...

Restrictions of Vue Data Objects

I'm currently pondering the optimal amount of data to store in a Vue data object. Imagine I have over 4,000 objects structured like this: personWithAppointment = { id: 1, appointment_id: 1, first_name: 'Jim', last_name: 'Jim&ap ...

The reactivity of external objects with the data options property in Vue.js 3 has been disabled

My app shares an external module with other applications by utilizing a global Javascript object. One of these apps is created using vue 2, and whenever the global object is updated in the external module, the option data property of vue 2 updates perfect ...

Using HTML, CSS, and jQuery to add a power sign to an input text box

Is there a way to enter square root and squared symbols into an input box using a calculator with buttons? When clicking a button, the value will be shown in the input box. For example, expressions like x²+x³ or 2√13 + 3√4. I'm primarily concern ...

Guide to Helping Users Customize JavaScript and CSS Files before Exporting as Embed Code

I have a vision to create a unique platform where users have the ability to log in to a customized dashboard, tailor their preferences, and then generate an embeddable code for age verification pop-ups on their websites. To kickstart this project, I'v ...