What could be the reason for inconsistent behavior of a CSS animation at times?

My current CSS animation attempt involves resizing a div element. I am trying to make the div expand in size starting from its center.

However, I am encountering an issue where in some sections of the website, the animation works perfectly while in others, the div grows from the upper left corner instead of the center.

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

I would appreciate insights on why this discrepancy is occurring and any suggestions on how to address it effectively.

Answer №1

Give this a shot!

To learn more about FlexBox, check out the documentation here: https://www.w3schools.com/css/css3_flexbox.asp

.circle {
  border-radius: 100%;
  display: flex;
  transition: all 2s;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.circle.red {
  background-color: red;
}

.circle.blue {
  background-color: blue;
}

.circle.out {
  width: 200px;
  height: 200px;
}

.circle.in {
  width: 0px;
  height: 0px;
}

.circle.animate {
  animation-name: bigger;
  animation-duration: 2s;
  animation-iteration-count: infinite;
}

@keyframes bigger {
  from {
    width: 0;
    height: 0;
  }

  to {
    width: 100%;
    height: 100%;
  }
}
<div class="circle out red">
  <div class="circle in blue animate"></div>
</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

Troubles with modal functionality in Ionic application involving ion-slide-box

Utilizing ion-slider to display images has been a seamless experience, except for one hiccup. If I navigate directly from the first full image back to the home screen, the slider ceases to function properly. To address this challenge, I have employed spec ...

jQuery causing trouble with AJAX in Rails

Currently, I am fetching a list of users from the controller side and generating the HTML code to append it. This is how I wrote the code: $.ajax({ type : "get", contentType : "application/json; charset=utf-8", url : "/users/sear ...

Position two div elements side by side

Here is the HTML code snippet that I am working with: <div class="demand page"> <div id="crumby-title"> <div class="page-icon"> <i class="fa fa-line-chart"></i> </div> ...

Height of a React Component

I have developed a React component for the homepage of my React application. Utilizing React Router, I am able to navigate through different components on the site. The issue I'm facing is that the homepage component does not occupy the entire page ex ...

The calender icon in Bootstrap4 datepicker input is unresponsive to clicks

template.html {% block content %} {% endblock %} <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin= ...

AngularJS: Modifying values in one div updates data in all other divs

The webpage appears as shown below: https://i.sstatic.net/IxcnK.png HTML <li class="list-group-item" ng-repeat="eachData in lstRepositoryData"> <div class="ember-view"> <div class="github-connection overflow-hidden shadow-oute ...

Adding a class to an img tag with TinyMCE

Currently, I am utilizing the TinyMCE editor as a standalone editor in my content management system (CMS). Within the CMS, there is an automatic setting that adds a curved border to any image tags within the cms div ID. In certain cases, I require the op ...

What is the best way to incorporate an image into the background of an HTML email?

My goal is to design an automated email script for sending birthday wishes. However, I am facing a challenge in setting up the background image for the email content. I want the image to be displayed behind the text, similar to how it appears on certain we ...

What is the best way to position two flexbox children in the center of a parent div with relative positioning?

I need help creating an animated hamburger menu icon with three lines that form into an X shape when clicked. Currently, I'm struggling to align the first horizontal line and the third one properly. Does anyone know how to make two flexbox children o ...

PHPMail is failing to properly format emails in HTML

Why is it that when I attempt to send an HTML email from a PHP script, Outlook displays it the same way as it appears in my database? Currently, my tool sends an email with the content stored in the $body variable like this: <p>Dear client,</p> ...

Ascending row placement

I'm currently working on a JavaScript timeline project, where clicking on an item in the left column reveals details in the right column. While there may be simpler methods to achieve this, the HTML code below appears to be quite elegant. Typically, ...

You can create a div with a variable width and center it within a parent container, even if the div's width is larger

Trying to articulate what I require. There are five Divs: a wrapper, div 1, div 2, div 3, and div 4. HTML: <div id="main"> <div id="one">1</div> <div id="two">2 <div id="four">4</div> </div> ...

Bootstrap: Troubleshooting Margin Problems

I am currently utilizing the Bootstrap sb admin template. I attempted to include 3 columns in a row, but encountered the issue of them being merged together with no space around them. I experimented by modifying the Bootstrap file through a CDN link and pr ...

Update your selection to ui-select and incorporate ngRepeat filters

Currently, I'm utilizing basic HTML select boxes to filter ngRepeat results in the following manner: <select ng-model="theFilter.choice"> <option value="">Any</option> <option value="Yes">Yes</option> <opt ...

CSS display:inline-block elements are not aligned in the same row

On my website, I have a grid of inline-block divs with a width of 33% each. The goal is to have 3 divs per line. Everything looks good, except for the first line where the first div takes up the entire line and its position is off. You can see it in action ...

Transmit a variety of information in a single Node.js request

I have a project where I need to retrieve data from multiple MongoDB tables and send it to the same landing page using a single GET request. The code snippet below shows how I am attempting to do this: as and bs represent different MongoDB database table ...

I am experiencing difficulties with my focusin not functioning properly for the input element that I added

I am working on a program that includes a dynamic table with the following structure: <table id="selectedItems"> </table> I plan to use jQuery to append elements to it like so: var i=0; $("#selectedItems").html(''); $("#sel ...

The vertical alignment of floated elements in HTML is not correctly positioned

The result of the code is not as expected. The right section should be aligned with the left, but it appears below instead. This is the code I am using: <!-- footer begin --> <footer> <div > ...

customized checkbox in Bootstrap 4

I'm facing an alignment issue with my custom ASP.NET Bootstrap 4 checkbox. I can't seem to get it to align properly within the form group row as shown in the picture – Issue with checkbox. The code for the form group row is as follows: <di ...

Create space in the bootstrap framework between an image and text

I'm trying to increase the space between the title/description and the icon image in my Bootstrap CSS layout. I attempted adding ms-5 to the div tag, but it didn't have the desired effect. NOTE: Please refrain from suggesting margin-right:5px as ...