transition-duration is ineffective in a particular div

Whenever I hover over the purple text, I want it to increase in size using the zoom property.

Here is an example:

I am facing two issues:

  1. The time duration does not seem to work even when I try to apply it within the hover and non-hover classes.

  2. When my cursor is positioned at the top of the purple text, it creates a constant loop of zooming in and out.

Below is the relevant code, any assistance would be greatly appreciated!

**I want the duration property to be applied within the initial class for a consistent effect when hovering and leaving the mouse pointer.

body {
  margin: 0 auto;
  overflow-x: hidden;
}

#divStyle1 {
  height: 90vh;
  background-color: #016087;
}

#purpuleLineBox {
  position: absolute;
  top: 25%;
}

#purpuleLine1 {
  background-color: #D52C82;
  height: 7vh;
  width: 30vw;
  margin-bottom: 30px;
}

#purpuleLine2 {
  background-color: #D52C82;
  height: 7vh;
  width: 38vw;
  margin-bottom: 30px;
}

#purpuleLine3 {
  background-color: #D52C82;
  height: 7vh;
  width: 42vw;
  margin-bottom: 30px;
}

#purpuleLine4 {
  background-color: #D52C82;
  height: 7vh;
  width: 50.5vw;
  margin-bottom: 30px;
}

#purpuleLine5 {
  background-color: #D52C82;
  height: 7vh;
  width: 52.5vw;
  margin-bottom: 30px;
}

div>p {
  color: white;
  text-shadow: 2px 2px black;
  font-weight: bold;
  font-size: 2vw;
  margin-left: 7px;
  position: relative;
  top: 5%;
}

.purpuleHover {
  zoom: 100%;
  transition-duration: 0.5s;
}

.purpuleHover:hover {
  zoom: 120%;
}
<div id="divStyle2">
  <main>
    <div id="purpuleLineBox">
      <div id="purpuleLine1" class="purpuleHover">
        <p>100% recyclable and bio-degradable</p>
      </div>
      <div id="purpuleLine2" class="purpuleHover">
        <p>Simulates the natural ripening process, organic</p>
      </div>
      <div id="purpuleLine3" class="purpuleHover">
        <p>The quickest way to achieve the perfect avocado taste</p>
      </div>
      <div id="purpuleLine4" class="purpuleHover">
        <p>Work with Mango, Banana, Peach, and another climacteric fruits</p>
      </div>
      <div id="purpuleLine5" class="purpuleHover">
        <p>The user interface on the bag shows when an avocado is fully ripen</p>
      </div>
    </div>
  </main>
</div>

Answer №1

To achieve the desired effect, make sure to include a transition-property, specifying the CSS property that the transition should target, rather than just using transition-duration. You can either declare them separately or combine them with the shorthand transition.

Furthermore, it's essential to replace zoom with transform: scale().

body {
  margin: 0 auto;
  overflow-x: hidden;
}

#divStyle1 {
  height: 90vh;
  background-color: #016087;
}

#purpuleLineBox {
  position: absolute;
  top: 25%;
}

#purpuleLine1 {
  background-color: #D52C82;
  height: 7vh;
  width: 30vw;
  margin-bottom: 30px;
}

#purpuleLine2 {
  background-color: #D52C82;
  height: 7vh;
  width: 38vw;
  margin-bottom: 30px;
}

#purpuleLine3 {
  background-color: #D52C82;
  height: 7vh;
  width: 42vw;
  margin-bottom: 30px;
}

#purpuleLine4 {
  background-color: #D52C82;
  height: 7vh;
  width: 50.5vw;
  margin-bottom: 30px;
}

#purpuleLine5 {
  background-color: #D52C82;
  height: 7vh;
  width: 52.5vw;
  margin-bottom: 30px;
}

div>p {
  color: white;
  text-shadow: 2px 2px black;
  font-weight: bold;
  font-size: 2vw;
  margin-left: 7px;
  position: relative;
  top: 5%;
}

.purpuleHover {
  position: relative;
  transform: scale(1);
  transition: transform 0.5s;
  transform-origin: top left;
}

.purpuleHover:hover {
  transform: scale(2);
  z-index: 1;
}
<div id="divStyle2">
  <main>
    <div id="purpuleLineBox">
      <div id="purpuleLine1" class="purpuleHover">
        <p>100% recyclable and bio-degradable</p>
      </div>
      <div id="purpuleLine2" class="purpuleHover">
        <p>Simulates the natural ripening process, organic</p>
      </div>
      <div id="purpuleLine3" class="purpuleHover">
        <p>The quickest way to achieve the perfect avocado taste</p>
      </div>
      <div id="purpuleLine4" class="purpuleHover">
        <p>Work with Mango, Banana, Peach, and another climacteric fruits</p>
      </div>
      <div id="purpuleLine5" class="purpuleHover">
        <p>The user interface on the bag shows when an avocado is fully ripen</p>
      </div>
    </div>
  </main>
</div>

Answer №2

Include a transition property in the following manner:

transition: transform 0.2s;

1) for the default state of the element 2) for the hover state of the element

By doing this, the element will smoothly animate in both directions

default state -> hover state

hover state -> default state

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

The radio button is not providing the necessary notification

I currently have the following elements on my webpage: Table rows that contain radio buttons A link labeled "Issue" that triggers a popup with one submit button A submit button labeled "details" that also triggers a popup The issue I am facing is as fol ...

The images fail to load on Mozilla browser and appear as blank spaces

My images are only displaying as white in Mozilla but fine on other browsers. I've tried using -moz without success. It's a simple fix that I can't seem to locate. Any help would be appreciated. Just a quick note, the images appear blank wh ...

Optimizing CSS for Landscape Letter Print Alignment

When attempting to print in letter size and landscape orientation, the two divs fail to align properly. However, when using "@size a4 landscape" for printing, the alignment issue is resolved. What could be missing from my print CSS that would allow them to ...

Guide to transforming Tailwind CSS into a class and saving it in a CSS document

Recently, I implemented Tailwind CSS to style my application. It has been a helpful tool, but I am looking to consolidate all the CSS into one file for better organization. I want to keep it separate from the HTML code. My attempt to convert the following ...

The animation loop completes and restarts from the initial keyframe

I have a CSS animation that I want to play through once and then stop at the final keyframe. However, currently it keeps returning to the initial keyframe and stopping there instead of reaching the end. The animation involves a title heading that gradually ...

Is there a way to ensure the alignment of items remains consistent, especially for the rightmost column, by enclosing them within a div element?

I'm currently working with Vue.js and using a UI component framework designed for it. I'm facing an issue where aligning numbers like 500 or 5000, as well as icons, is proving to be difficult. The numbers in the rightmost column need to be aligne ...

What is the process for implementing custom CSS styles in Cognos?

I've been working on creating Cognos reports and I'm looking to change the overall design of some specific ones (prompt pages and report pages). Is there a way for me to use different custom CSS files for each individual report? If that's ...

triangle as a backdrop

Looking for a unique design for your website background? How about a triangle split with black on one side and white on the other, like this image? I can't seem to find this online, so any help would be greatly appreciated. Is it possible to achieve t ...

Leverage an HTML table to serve as a data source for populating a Kendo UI template

My latest creation is a unique service that generates HTML tables based on request parameters. The current implementation returns the data as an HTML page in string format. Here's a sample output: <!DOCTYPE html> <html> <head> ...

Can a shape similar to an inverted circle be created using CSS and jQuery?

I'm stumped on how to create an inverted circle in the corners. I've included a picture for reference. https://i.stack.imgur.com/jeNdh.jpg Is it feasible to achieve this effect using CSS3 or maybe jQuery? ...

How can I adjust the font size in a TextField when it is in focus?

As a novice in ReactJS, I am currently utilizing materia-ui to design a page. I am looking to make a custom change on a TextField where the font size adjusts when text is entered. However, adjusting the font size creates too much space between the label a ...

Unable to generate file with Compass

In my attempts to compile a project using compass, I have experimented with both the gui app and the command line. However, I consistently encounter the same error message in both cases: "Nothing to compile. If you're trying to start a new project, yo ...

Ways to eliminate spacing from a bullet point in a list?

Is there a way to eliminate indentation from ul? I attempted adjusting margin, padding, and text-indent to 0, but with no success. It appears that setting text-indent to a negative value works - but is this the only solution for removing the indentation? ...

"Creating a sleek and streamlined navigation bar in Bootstrap-4 without

<ul class="nav navbar-nav"> <li class="nav-item-dropdown"> <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false> SLIDES ...

Padding on a flex item nudges a neighboring flex item out of place

Encountering an issue - within a div container, I have 4 nested divs using the grid system. Oddly enough, the third div in the grid is not behaving as expected. When setting a margin-bottom for this div, instead of creating space at the bottom, it pushes ...

What is the best location to include my JavaScript code in WordPress?

Alright, so I've got this world map on one of my WordPress pages and here's an example of the code: <area onmousedown="modifyImage('world_map_01', './images/map/asia.jpg')" onmouseout="modifyImage('world_map_01', ...

Guide to showcasing associated information in HTML using Angular 7

I am a beginner with Angular 7 and I am attempting to showcase a product's color on the HTML side using Angular 7 but have not been successful. Below are my tables; Product Id Name Color Id Name ProductColorRelation Id ProductId ColorId In ...

Django failing to detect empty URL configuration

Hey there! I'm new to this, and I was trying out a tutorial on py/django. The web server is up and running, but it's only showing the default page: Even though my urls.py has the default page set. urls.py from django.contrib import admin from d ...

Looking for a solution to fix the VueJS calculator that only works once?

My calculator project using VueJS, HTML and CSS is almost complete. However, I'm facing an issue where it only works once. For example, if I input 6x3, it correctly gives me 18. But if I then clear the result and try to input a new calculation like 3 ...

Using the feColorMatrix SVG filter in CSS versus applying it in JavaScript yields varied outcomes

If we want to apply an SVG filter on a canvas element, there are different ways to achieve this. According to this resource, we can apply a SVG filter to the CanvasRenderingContext2D in javascript using the following code snippet: ctx.filter = "url(#b ...