CSS can always surprise with its unexpected animations

Currently developing a static website with CSS animations:

*
{
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    -ms-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;     
}

All pages are animated similarly, except for one HTML document that includes input elements and a textarea:

<form action="script/contact-form.php" method="post">
    <b>Full name:</b><br/>
    <input type="text" name="name" /><br/>

    <b>Subject:</b><br>
    <input type="text" name="subject" /><br/>

    <b>E-mail:</b><br>
    <input type="text" name="email" />
    <br/><br/>

    <b>Your comments:</b><br/>
    <textarea name="comment"></textarea>
    <br/><br/>

    <input type="submit" value="Submit" />
</form>

Even after trying to disable the animation using this code:

form, input, textarea
{
    -moz-transition: none;
    -webkit-transition: none;
    -o-transition: color 0 ease-in-out;
    -ms-transition: color 0 ease-in-out;
    transition: none;   
}

The entire page remains animated, unlike other pages utilizing the same stylesheet. Check it out here: . Clicking on other pages produces different effects.

This issue is becoming frustrating, and any assistance would be greatly appreciated.

Thank you in advance.

Answer №1

Identifying the Issue

Your statement:

You mentioned that the entire page is being animated for some unknown reason.

This is actually the expected outcome when utilizing this code block:

* {
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    -ms-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;     
}

The CSS selector * signifies that any CSS attributes designated for that selector will be applied to every element within your webpage.

The use of all in the property transition implies that any animatable properties of those elements will indeed be animated.

Hence, combining the CSS selector * with the CSS property transition: all results in animation of all possible animatable properties across every HTML element present on your website.

Resolution 1 : Target Specific Elements for Animation

An alternative approach could involve the following adjustment:

/** Remove this code
* * {
*    -webkit-transition: all 1s ease-in-out;
*    -moz-transition: all 1s ease-in-out;
*    -o-transition: all 1s ease-in-out;
*    -ms-transition: all 1s ease-in-out;
*    transition: all 1s ease-in-out;     
* }
*/

.animate, .animate * {
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    -o-transition: all 1s ease-in-out;
    -ms-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;     
}

Following this modification, append class=animate to each element you wish to animate within your HTML:

<ul class="animate">
  ...
</ul>

Several other implementations can also be explored; however, this represents one of the simpler options. For optimal strategy, refer to "Additional enhancements" below.

Resolution 2 : Disable Unwanted Animations

Trying the following action might resolve the issue:

form, input, textarea {
    -moz-transition: none;
    -webkit-transition: none;
    -o-transition: color 0 ease-in-out;
    -ms-transition: color 0 ease-in-out;
    transition: none;   
}

You indicated testing this solution, but it wasn't evident in your provided code. Ensure it is positioned AFTER the * selector.

Further Enhancements

To ensure better performance and avert unexpected outcomes, it's advisable to solely apply animations to specific properties and elements slated for animation.

For instance, if you aim to animate both width and height of your div elements, consider this format:

div {
    -moz-transition: width 2s, height 4s;
    -webkit-transition: width 2s, height 4s;
    -o-transition: width 2s, height 4s;
    -ms-transition: width 2s, height 4s;
    transition: width 2s, height 4s;
}

If restricting animation to solely the background of your #navigation li elements is desired, utilize a structure like the one presented below:

#navigation li {
    -moz-transition: background 1s ease-in-out;
    -webkit-transition: background 1s ease-in-out;
    -o-transition: background 1s ease-in-out;
    -ms-transition: background 1s ease-in-out;
    transition: background 1s ease-in-out;
}

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

Creating an infinite scroll with a gradient background: a step-by-step guide

I am currently working on a project to develop an infinite scrolling webpage with a dynamic gradient background that changes based on the user's scroll position. While researching, I came across some code for infinite scrolling using time and date. I ...

The innovative technique of using pure CSS to secure the bottom edge of a div to the viewport

Is there a way to keep two container divs positioned x pixels from the bottom of the viewport without using position absolute|fixed? I want them to remain as position: relative for proper DOM flow. Searching for a CSS-only solution that works in IE7+. Mos ...

An issue arises in CSS when the styling is not correctly implemented on the HTML elements

I am currently trying to recreate this code on my own page: https://codepen.io/Vlad3356/pen/PoReJVg Here is the code I have written so far: https://codepen.io/Vlad3356/pen/GRxdMPz I'm puzzled as to why, when I click on a star in my version of the co ...

Tips on properly styling HTML using the BEM naming convention

I'm trying to implement BEM naming in my project, but I'm having trouble with how to name elements within elements. BEM guidelines state that elements of elements should not exist. How should I approach naming them correctly? <div class="cont ...

Change SVG path data into a range of 0 to 1 in order to utilize it as a clip path with objectBoundingBox

My SVG shape, exported from Illustrator as a clipping path, is quite complex. The issue I'm facing is that objectBoundingBox restricts path data to the 0-1 range, but my path data exceeds this range. Here is the current code I'm using: <svg& ...

Designing a Curved Stepper Component in the Shape of an S

I've been attempting to create a custom stepper component with an S-curve shape using React, but so far I haven't been successful. I even tried utilizing the MUI Stepper component and experimented with pure HTML and CSS, but couldn't achieve ...

What is the best way to set the width of an element to 100% while accounting for padding

My dilemma involves an HTML input field. The input currently has padding: 5px 10px;, but I need it to occupy 100% of its parent div's width (which is fluid). If I try using width: 100%;, the input ends up being wider than intended due to the padding ...

Validating a form using HTML5 in a modal designed with Bootstrap

As a newcomer to jquery and javascript, I am facing a challenge. I want the form to open when the "Open Modal" button in the modal is clicked. After that, upon clicking 'Save' in the modal, I need it to validate the HTML5 form and if validation ...

Is it possible to connect ng-model with a style tag?

Is it feasible to create a basic template editor using angularjs where an input field with an ng-model can be connected to a style tag to control the css on an entire page rather than applying it to a specific element with inline styling? Could something ...

What is the best way to ensure an input field and a button are aligned perfectly within the same div tag and of equal height?

During a recent HTML-CSS project, I encountered an issue where I struggled to ensure that two elements within a div tag were the same height. The elements in question were an input field and a button with an icon. Here is a snippet of the relevant HTML cod ...

Difficulty with Bootstrap 4 mobile navbar dropdown feature

<div class="baslik baslik1 baslik2 "> <nav class="navbar bg-light navbar-light navbar-expand-sm sticky-top "> <a href="./index.html" class="navbar-brand"><img src="img/512x512logo.png" ...

Ensure the form is properly validated before initiating the submission process on 2checkout

Attempting to prevent the form from being submitted, I implemented the code below. Typically, this method works perfectly fine. However, when integrating 2checkout js (), it does not function as intended. <form onSubmit="validate(); return false;" meth ...

Prevent form from being resubmitted upon browser refresh

Currently, I have a form where users input data and it searches the database to display results. The issue arises when the user refreshes the page as it triggers an alert about resubmission. Although the data remains the same upon resubmitting, is there a ...

How to locate a specific object by its ID within a JSON structure embedded in an HTML template

I am currently working on the page where I display posts. Within my controller, I have: export class PostsComponent implements OnInit { posts$: Object; users$: Object; constructor(private data: DataService) { } ngOnInit() { this.data.getPo ...

Activate a CSS class on click using JavaScript

Having a bit of trouble as a beginner with this. Any help would be much appreciated. This is the code in question: HTML: <div class='zone11'> <div class='book11'> <div class='cover11'></d ...

Is there a way to make divs expand on top of existing content when hovering over them, in order to avoid needing to scroll through overflow content? I am currently working with

I am working with 9 boxes contained within divs, each box includes data that exceeds the size of the box itself (represented by Some Text repeated for demonstration purposes). I am seeking a solution where hovering over any box will cause it to enlarge and ...

What is the functionality of the disabled attribute on an option tag within a dropdown select menu?

I am working with a code snippet that involves understanding how the attribute:disabled functions on an <option> within a <select> element! Let's say I have a dropdown for ratings and I select the 5-star option (★★★★★). Upon sel ...

Guide on incorporating HTML data into an existing webpage

Requesting assistance in creating an HTML page that features a dynamic drop-down menu. The drop-down should trigger a list to appear upon selection, which can be sourced from either a text file or plain HTML document. The envisioned functionality involves ...

align the text to the left in the center of the page

.center { margin: 0 auto; display: table; } .center .content { display: table-cell; } These CSS styles are used to center align the container with the class .center, while also keeping its contents (in .content) left aligned: <div class="center" ...