Tips for adjusting animations using @media queries

My animation, , appears correctly on mobile but not desktop. It is too wide on desktop and I have tried adjusting the CSS without success.

@media (max-width: 5000px) and (min-width: 768px) 
{.contact::before.contact::after {content: attr(data-text);
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 100%; 
}} 

Despite multiple divs within one query, my CSS checker does not flag any issues, so theoretically it should work.

Changing width: 100%; to width: 50% in the CSS works, but then the width is too small for mobile.

The HTML code is:

<div class="contact" data
text="CONTACT">CONTACT</div>

CSS FOR ANIMATION

page-id-1239 { background: #000; display: flex;
align- 
items: center;
height: 100vh;
justify-content: center; }
.contact {
font-family: arial;
position: relative;
color: #fff;

text-align: center;
font-size: 7rem;
max-width: 1200px;
margin: 0 auto;
}

.contact::before
.contact::after {
content: attr(data-text);
position: 
absolute; top: 0;
left: 0;
width: 100%; height: 100%;
}

.contact::before {
left: 2px;
clip: rect(79px, 1200px, 86px, 0);
text-shadow: -1px 0 red;
background: #000;
animation: brasil-anim-2 1s infinite linear alternate- 
reverse;
}

.contact:after {
left: -2px;
clip: rect(79px, 1200px, 86px, 0);
text-shadow: -1px 0 blue
000; animation: brasil-anim-1 1s infinite linear alternate- 
reverse;
Animation-delay: -1s;
}
@keyframes brasil-anim-1 {
0% {
Clip: rect(20px, 1200px, 76px, 0);
}
20% {
Clip: rect(19px, 1200px, 16px, 0);
}
40% {
Clip: rect(16px, 1200px, 3px, 0);
}
60% {
Clip: rect(62px, 1200px, 78px, 0);
}
80% {
Clip: rect(25px, 1200px, 13px, 0);
}
100% {
Clip: rect(53px, 1200px, 86px, 0);
}
}
@keyframes brasil-anim-2 {
0% {
Clip: rect(79px, 1200px, 86px, 0);
}

20% {
Clip: rect(20px, 1200px, 30px, 0)
}
40% {
Clip: rect(25px, 1200px, 5px, 0)
}
60% {
Clip: rect(65px, 1200px, 85px}

80% {
Clip: rect(120px, 1200px, 145px, 0)
}
100% {
clip: rect(95px, 1200px, 75px, 0)
}}

Answer №1

.contact::before.contact::after is considered an invalid selector. To correctly address both ::before and ::after, you should write it as follows: To elaborate, the original selector is not technically invalid, but it does not target any existing elements. It implies selecting an after element with the class 'contact' that is positioned ::before an element of contact. Because ::before and ::after cannot have classes, this selector will not match anything on a webpage. To target two distinct elements, you need to separate them with ,:

.contact::before, .contact::after {
  /*your css rules here*/
 }

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 it possible to incorporate Excel files into a web-based system that only supports HTML?

Currently, I am working on an HTML-based system where my supervisor has specified that only HTML can be used to keep things easy and simple. My question is: Can Excel files be added to the HTML-based system, and if so, is it possible to work with, save, a ...

Do you have a title for the pre code section?

When it comes to tables, there's a <caption>, and for figures, there's a <figcaption>. But what tag should be used for pre? (The goal is to provide a caption for a listing, but since the <listing> tag has been removed, <pre& ...

The title tag's ng-bind should be placed outside of the element

When using ng-bind for the title tag inside the header, it seems to produce unexpected behavior. Here is an example of the code: <title page-title ng-bind="page_title"></title> and this is the resulting output: My Page Sucks <titl ...

"Troubleshooting: Issues with jQuery Counter Functionality

Hey there, I'm new to JavaScript and jQuery! I've got this form set up with Bootstrap's disabled class: Note: the 'disabled' class in bootstrap properly disables and enables the button based on conditions. <form action="" met ...

Adjust the navigation bar for smaller screens

I am diving into my first project using Bootstrap and am currently in the process of setting up the navbar. My goal: When the XS model is activated, I want to adjust the font size of the header, modify the height of the navbar, and left-align the header. ...

Troubleshooting: Issues with Mod_rewrite affecting CSS, JS, and Image functionality

Today marks my first time posting a query in this forum. I'm currently facing an issue with mod_rewrite. Below is the structure of my filesystem: site_new/stylesheets/layout.css site_new/javascript/somescript.js site_new/hallendetails.php ...

What is the best way to integrate HTML code within a JavaScript function?

I need the HTML code to execute only when a specific condition in JavaScript is met. Here is the JavaScript code: <script type="text/javascript"> $(document).ready(function () { if(window.location.href.indexOf("index.php") > -1) { ...

Adjust the vertical size of the background hue on the span element within the text

Can the height of the background color in my span be adjusted? HTML <span class="highlight">Some highlighted text</span> CSS .highlight{ font-family: 'Roboto', sans-serif; font-weight: 300; font-size: 1.5em; backgr ...

Dynamic color change in SVG

I am facing an issue with changing the color of svg images in a menu list using the filter CSS property. Even though I have obtained the correct filter value from a library that converts hex to CSS filter, React seems unable to set this property on the ima ...

Ways to dynamically incorporate media queries into an HTML element

Looking to make some elements on a website more flexible with media rules. I want a toolbar to open when clicking an element, allowing me to change CSS styles for specific media rules. Initially thought about using inline style, but it turns out media rul ...

How can you apply a class to a different element by hovering over one element?

Is there a way to darken the rest of the page when a user hovers over the menu bar on my website? I've been playing around with jQuery but can't seem to get it right. Any suggestions? I'm looking to add a class '.darken' to #conte ...

PayPal form without encryption

Once upon a time, I recall creating a button in Paypal which provided me with a standard HTML form. However, now everything seems to be encrypted. Is there a way to retrieve an unencrypted format? I need to be able to manually adjust the price using jQuer ...

Switch videos within the video tag as you scroll

I am trying to implement a video tag within a div element on my website. Here is the current code: <div class="phone" align="center"> <div class="phone-inner"> <video width="100%" height="100%" autoplay="" loop="" muted id="phonevideo ...

Guide to dynamically refreshing a section of the webpage while fetching data from the database

I'm currently developing a website using PHP & MySQL where some queries return multiple records. Each record has its own dedicated page, allowing users to navigate between them using arrows. So far, everything is working smoothly. However, I've ...

The button fails to function properly after loading a partial view using AJAX

Having an issue with my page that contains two buttons - Next and Previous. These buttons are supposed to load a table in a PartialView. The problem arises when I press the button for the second time, it doesn't work as expected. Below is the code sn ...

Is there a way to smoothly navigate back to the top of the page after the fragment identifier causes the page to scroll down?

I do not want to disable the functionality of the fragment identifier. My goal is for the page to automatically scroll back to the top after navigating to a specific section. This inquiry pertains to utilizing jQuery's UI tabs. It is crucial to have ...

`The Best Times to Utilize Various Image Formats Within a Single Webpage`

If I have two identical images displayed on a page at different sizes, what is the best option for optimizing performance? On one hand, using an image already sized correctly can improve performance, especially on mobile devices. On the other hand, using t ...

Issue with ThreeJs: Difficulty loading separate images on top and bottom surfaces

I've been trying to place different textures on the top and bottom sides using Threejs to display unique images on each side. However, I'm encountering an issue where the same image is being displayed on both the top and bottom sides. Below is th ...

Instructions on creating a number increment animation resembling Twitter's post engagement counter

I've been attempting to replicate the animation seen on Twitter's post like counter (the flipping numbers effect that happens when you like a post). Despite my best efforts, I can't seem to make it work. Here is what I have tried: $(fun ...

From transitioning from a radio button's checked indicator to a complete button

I'm in the process of customizing my WordPress plugin and seem to be struggling with styling the radio buttons. For reference, you can find the code snippet here: https://jsfiddle.net/cd3wagvh/ The goal is to conceal the radio buttons and modify the ...