Guide on implementing several changes to a single element

I am working on creating a mosaic of triangles using an image that is rotated and placed in a grid layout. My goal is to animate the rows of the layout to slide from different directions to their final positions using transform (translate). The issue I am facing is that the animation starts with the image in its original orientation instead of the rotated one. How can I animate the rotated image?

View the attached image here.

EDIT: You can find my code below. I believe there might be a better approach to this, but for now, I just need it to work if possible.


#loader-container {
  width: 50vw;
  height: 12vw; 
  max-width: 830px;
  position: relative;
  margin: auto;
}
...
(Continued CSS code)

<div class="top-container">
      <div class="top">
         ...
         (Continued HTML code)

For the full code, visit this link.

Answer №1

It's difficult to provide an answer without seeing your code, but from what you've described, it seems like the issue might be related to the transform property being overwritten in the animation.

Here is a simple example:

<div class="triangle"></div>
.triangle {
  border: 20px transparent solid;
  border-right-color: red;
  display: inline-block;
  animation-name: example;
  animation-duration: 1s;
  transform: rotate(45deg);
  animation-fill-mode: forwards;
}

@keyframes example {
  from {
    transform: translate(0px, 0px) rotate(45deg);
  }
  to {
    transform: translate(1000px, 0px) rotate(45deg);
  }
}

[EDIT] I have some suggestions after reviewing the provided code.

It appears that you are declaring the transform property multiple times for the same element. In CSS, the last declaration always takes precedence over previous ones. To resolve this issue, consider one of the following solutions:

  1. Restructure your HTML and CSS as shown below:
<div class="triangle topleft green column7 row2"></div>

Can be changed to:

<div class="triangle-holder topleft column7 row2">
    <div class="triangle green"></div>
</div>

This approach allows you to have different transforms on separate elements without conflicts. The transform: rotate() applies to the .triangle class, while transform: translate() applies to the .triangle-holder.

  1. Eliminate the use of transform: rotate() altogether by utilizing borders for triangular shapes (refer to the earlier example). This method works well for 90-degree rotations only.

  2. Avoid using transform: translate() and opt for margin or top/left properties for positioning instead.

  3. Animate each triangle uniquely to consolidate transforms into a single transformation.

I recommend the second option as it involves minimal modifications to your existing code and is widely supported across browsers for creating CSS triangles.

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

Converting HTML to Plain Text in Vue.js

Is there a way to convert HTML to plain text using vuejs? <ol> <li>The quick brown fox jumps over the lazy dog</li> <li>The quick brown fox jumps over the lazy dog</li> <li>The quick brown fox jumps over the ...

Change the color of the final two letters in the word within h1

There is one h1 heading in my code, and it looks like this: HTML <h1>AwesoME</h1> CSS h1 { color:#eee } h1:last-word { color:#000 } I want to only change the last two characters of the h1 text. Is it possible to achieve this using JavaScr ...

Achieving a border around the text within a UL element

I am currently working on styling a menu using a UL. However, I encountered an issue where adding a border makes it extend across the whole screen due to the li elements being set to display: block. I do not want to specify a fixed width for these elements ...

Random unwinding animation of UIView

I am facing a challenge where I have an area on the screen that covers about 2/3 of the total screen area. Within this area, there are two objects - a MKMapView and a UITableView. When a button is pressed, I want to switch the sizes of these two objects wi ...

The dropdown menu is extending beyond the bounds of the screen on mobile devices

When viewing my website on a mobile device, the select dropdown is going off the screen. I am using the bootstrap class form-control. Here is my code: <select name="service" formControlName="service" class="form-control shadow-none" style="width:100%"& ...

Dynamic Text Effects and Animated Background Alterations

I'm facing a challenge and could use some guidance. https://i.sstatic.net/VKm2P.jpg Is there a way to incorporate animations similar to the image shown? I aim to have the background color and text smoothly transition to different hues 1 second after ...

Issues persist while attempting to save sass (.scss) files using Atom on a Mac

When attempting to work with sass files, I encountered an error message every time I tried to save the file: Command failed: sass "/Users/bechara/Desktop/<path of the file>/test.scss" "/Users/bechara/Desktop/<path of the file>/test.css" Errno: ...

What is the reason behind the change in style hierarchy when using ':last-child'?

I found myself in a confusing situation where using :last-child is affecting how parent classes are being applied. The task at hand is to style the last element in a list of elements. However, upon using :last-child, the priority of styles shifts and one ...

OO Design for CSS Style Elements

I'm curious about the most effective way to implement objective-oriented CSS for quick and clean reuse of components. Scenario 1: HTML: <button class="button button-submit">Submit</button> CSS: .button { /* basic styles */ } .button ...

Objects that incorporate a mixture of relative and absolute positioning properties

I am looking to display elements that are relatively positioned next to each other but absolutely positioned above everything else. You can view the desired rendering here and my attempt at achieving it in the fiddle below (or this codepen). Thank you! ...

Adjust the image's width to match the width of the browser

I am seeking assistance on how to resize an image to fit the width of the browser. Specifically, the image I want to resize is my header image and I want it to span the entire screen width. Additionally, I need to overlay a div on top of the image. Curren ...

Offset the content from the border within a container that includes a scrollbar

The containing element has some content that is set to have a fixed height and overflow: auto; as shown in the JSFiddle link provided. When scrolling through the text, you will notice that the border comes into contact with the text both above and below. ...

How to horizontally align a dropdown menu in a container using Bootstrap 4 beta

I'm having trouble figuring out how to center my select element within my div. <!--PAGE CONTENT--> <main role="main" class="container-fluid"> <div class="row text-center justify-content-center" style="border: 1px solid red; ...

Tips for removing a specific shape from an HTML element

After spending 48 hours immersed in the world of clip, clip-path, masking, and all things CSS-related, I find myself unable to crack the code on the following challenge: Imagine a red background filling the body of the page. Layered on top of this is a wh ...

What is the best way to integrate a button within a datatable cell to display additional details in a popup window?

I am seeking help with datatable.js. I would like to insert a button inside the cells of the datatable columns to expand and display the detailed content of each cell. When I click on the red button, a popup modal should appear showing the full list of con ...

There is an overflow issue where content on the left side is being hidden when the overflow is set to auto

I am attempting to display a content box consistently on both desktop and mobile by utilizing a fixed width and overflow property. :root { --box: rgb(20, 33, 150); --box1: rgb(55, 75, 255); --background: rgb(147, 158, 255); } body { -we ...

Can someone advise me on the best way to make a chain of circles move in a linear path across my canvas, resembling a wriggling worm?

void initialize(){ size(800,800); background(0); } void animate() { int[]worm = {20,40,60,80,100,120}; fill (255,0,00); for (int i = 0; i < worm.length; i ++){ ellipse (i*6, 100,10,10); } } I want to create a straight horizontal moveme ...

Steps for creating a fade-in effect using CSS on an input set that is displayed as a block

I can't seem to figure out a solution for my current issue. I want my inputs to be hidden with opacity: 0 on page load and then appear later with full opacity, but only if they are displayed in block format in order to move down the page instead of in ...

Utilizing the checked or clicked property of radio buttons for my specific scenario

Hello everyone, I am currently working on Rails 3.2.13 and have implemented the following script in my view file. Whenever a user selects 'Other' as their owner type, I need the div with id=group_user_id to open and save the operation at the end. ...

Utilizing onBlur and onFocus events in React to implement a dynamic menu that shows or hides

Currently, I am in the process of mastering React and developing a small online electronic store. Within my project, there is a tab labeled "View Store". My goal is for a small, hidden column to appear when a user clicks on this tab, revealing text or imag ...