Can keyframes animation be applied to pseudo-elements?

Is it feasible to utilize CSS keyframes animation on pseudo-elements like 'before' and 'after'? I'm creating a web service for mobile devices and I want to make an element blink without affecting the element itself. I've thought of two ways to achieve this: one is by covering the element with another element and animating that, and the other is by using a pseudo-element, but it doesn't seem to be effective.

CSS:

.fadeElement {
  background-color: #000000;
  width: 60px;
  height: 60px;
}
.fadeElement:after {
  display: block;
  content: '';
  position: relative;
  height: 100%;
  width: 100%;
  z-index: 500;
  background-color: rgba(249, 4, 0, 0.5);
  animation-name: 'fade';
  animation-duration: 2s;
  animation-iteration-count: infinite;
  -webkit-animation-name: 'fade';
  -webkit-animation-duration: 2s;
  -webkit-animation-iteration-count: infinite;
}
@keyframes 'fade' {
  0% {
    opacity: 0;
  }
  40% {
    opacity: 0.5;
  }
  60% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}
@-webkit-keyframes 'fade' {
  0% {
    opacity: 0;
  }
  40% {
    opacity: 0.5;
  }
  60% {
    opacity: 0.5;
  }
  100% {
    opacity: 0;
  }
}

HTML:

<div class="fadeElement"></div>

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

Is there a way to change an element's display to 'block'? (see more information below)

I'm having an issue with my event listener for a button that is supposed to change the css of #popUpForm. It seems to only work when I add inline css directly to #popUpForm. Is there a way to achieve this without using inline css and instead setting t ...

Tips for repositioning the window when linking to a different section of a website

As a beginner in HTML and CSS, I am currently working on adding a navigation bar to my one-page website. I want the navigation bar to smoothly guide users to different sections of the page when they click on a link. To achieve this, I am using anchors and ...

Graphic descending within container

Struggling to design some divs for image display, I encountered a problem where the image shifts down by 3 pixels. It seems this is due to a 3 pixel margin on the container div, but I'm puzzled as to why it affects the image position. padding:0; marg ...

Is it possible to generate a star rating system from an image using a decimal value?

Recently, I have been eager to convert a number into a star rating and stumbled upon this helpful post here: . The post perfectly explains what I am looking to achieve. Despite following the instructions provided, I am facing difficulties getting it to fun ...

adjusting the arrangement of flex elements

I have a container with multiple divs and am utilizing the flexbox model. My goal is to achieve a specific layout using CSS without altering the order of the div tags. https://i.sstatic.net/jdAK6.png The desired outcome is to have the div with the value ...

Center-align a list with items floated to the left in a d-flex container

I'm attempting to create an inline list that resembles a grid with as many cards arranged horizontally as possible. However, I've encountered a problem - when I float the list items to the left, the text centering no longer functions and the list ...

Is there a way to make all Bootstrap column heights equal using only jQuery?

I am currently working on matching the heights of two columns without using an existing library like match-height.js. In this specific case, I have a row with 2 columns where the first column contains a centered black square and the second column contains ...

Firm emblem obstructs individual avatar

I have noticed a strange issue with my header layout. When I include the hamburger menu and user icon, they align perfectly in a row. However, as soon as I add the company logo, the user icon shifts downward and breaks the alignment. I have tried adjustin ...

Anchor tags created using JQuery will remain on the same page without redirecting

Presented below is the code I have utilized to construct the anchor tag along with its content. $('div#right-slide').html("<a href=\"http://www.XXXXXXXXXXXX.info/limited-specials/\" ><h1 id=\"specials\">Click Here ...

.display() and .conceal() functions malfunctioning

I'm in the process of creating a calendar system using the Codeigniter framework. My goal is to display a specific div every time a day cell in the calendar template is clicked. These divs are generated through a PHP for loop and populated from the d ...

Implementing a dynamic header image that adjusts its resolution based on the device and pixel density for

After finishing a design in Sketch, I have 3 unique layouts with header images displayed below: https://i.sstatic.net/fG5T3.png To ensure the height is consistent and to crop the image appropriately on different devices, I export the following images fro ...

Button from Bootstrap extends beyond the page on mobile devices

I am facing an issue with my button. It looks great on desktop, but when I switch to the mobile version, it goes beyond the screen width like in the image below: https://i.sstatic.net/69Zbs.png 1) How can I prevent this from happening with the code provi ...

Unique CSS specifically designed for consecutive elements listed in succession

I have a list of notes in a document, but occasionally I may include some document updates (such as "Document closed", "Revision made"...). Here is the basic HTML structure of a document and its notes: <p class="document-note">My note</p> < ...

Display or conceal Badge/Label based on Publication Date surpassing specified amount of days

I stumbled upon this code snippet function check_post_age($days = 5) { $days = (int) $days; $offset = $days*60*60*24; if ( get_post_time() < date('U') - $offset ) return true; return false; } if ( check_post_age(10) ...

IE7 z-index issue with incorrect stacking order

Visit this jsFiddle link. When using IE7, the code in the jsFiddle above shows the dropdown (.sbOptions) positioned beneath the next selectbox element (.sbHolder). Even though .sbOptions has a z-index: 100;, it is still being displayed under .sbHolder. ...

There appears to be an empty void on the website

If you could kindly click on this link & use CTRL + F to search for the text "Info", you will see a visual representation similar to the image below. There seems to be quite a bit of empty space below these texts. I experimented with padding, display: ...

The transparency of the navigation menu is perplexing to me. I am unclear as to the reasoning behind it. I desire a

I am currently using a pre-made WordPress theme. Recently, I incorporated particles.js as the background for my website. The issue I am facing now is that my navigation menu is blending into the same color as the background. I have tried defining a separat ...

Is there a way to achieve a double background color effect in CSS while ensuring that the text is centered within the second background color element?

How can I achieve a layout similar to the one shown in this image: ul menu li tags Should I use two tags for each element? Here is an example: <ul class="menu"> <div class="outside"><li class="inside"><a href="#">Firefox</a ...

How can I align the <li> items within a <ul> on the right side using Bootstrap?

How can I align <li> elements in one <ul> on the right side to be displayed in a single line? <nav class="navbar navbar-inverse"> <div class="container-fluid"> <div class="navbar-header"& ...

Creating a custom dialog box using JavaScript

How can I create a customized dialog box in the center without displaying "the host name says..." using CSS? function myFunction() { alert("Record Save"); } Thank you in advance! ...