On hover, HTML5 animations smoothly transition a dashed border inward

I'm in the process of creating a drag and drop module and I want to ensure that as the user drags an item, the dashed line around the outside moves inward and the box changes color. However, I don't want the appearance of the dashed line to change. One idea is to animate the movement of the dashed line along the edge of the box.

.

  • How can I prevent the contents from jumping by applying absolute positioning to disconnect them from the border morphing?
  • Is there a way to smoothly animate the border moving in and out using CSS3?

Link to example

HTML:

<div class="drag-drop">
  <div class="drag-drop-border">
    <div class="contents">
      xx
    </div>
  </div>
</div>

CSS:

.drag-drop {

  .drag-drop-border {
    border: 2px dashed pink;
  }

  &:hover {
    padding: 15px;
    background: gold;
  }

}

https://i.sstatic.net/O8Y4j.png https://i.sstatic.net/nzLgI.png

Answer №1

Here is a suggestion to achieve the desired effect:

.container {
  width: 200px;
  height: 200px;
  border: 1px solid black;
  position: relative;
}

.container::before {
  content: "";
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  bottom: 10px;
  background-color: rgba(255, 0, 0, 0.5);
  z-index: -1;
  transition: all 0.5s;
}

.container:hover::before {
  top: 20px;
  left: 20px;
  right: 20px;
  bottom: 20px;
}
<div class="container">

</div>

Answer №2

To create a seamless border transition effect, consider incorporating the following CSS snippet into your code:

{
    transition: 0.5s padding ease-in-out;
}

Feel free to adjust the parameters in the transaction to suit your specific needs.

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

Unlocking the Process of Sending Images to a Server and Accessing Them from the Client End

Dealing with two different API endpoints for image upload has presented challenges. One endpoint is for the local server (http://localhost:8000/api/image/upload) while the other is for the live server (). Unfortunately, an issue has arisen specifically on ...

Execute a function within useEffect continuously until the contract is fully loaded

When I make the call contract?.methods.name().call() within the same scope as loading providers, everything works perfectly fine. It also works fine when I do a page reload. However, if I make the call contract?.methods.name().call() in another useEffect, ...

What is the best way to add hyphens between words in PHP code?

Here is the code snippet and the desired output: ('nice apple'),(' nice yellow banana'),(' good berry ') To achieve the desired output: ('nice-apple'),(' nice-yellow-banana'),(' good-berry ') ...

Encountered a Server Error: Invalid hook call. Hooks are restricted to being called within the body of a function component specifically in _app.js

As someone new to React and Next JS, I am facing an issue with setting initial auth user data on the initial load from the __app.js file. Whenever I try to use dispatch, it throws an error saying "Invalid hook call". I understand that calling hooks in the ...

Mobile devices with a horizontal scroll

Having trouble with side scrolling on mobile devices. I've set two @media queries for tablet and mobile. Visit dev.bdbshop.com @media only screen and (max-width: 767px) { .wrap { max-width: 300px; } Could the issue be related to this? Any suggestio ...

Tips on how to modify the Firestore field named `likes` by incrementing or decrementing one

I have encountered an issue while trying to update a number field in Cloud Firestore. Despite following the official document and writing the code, it did not produce the desired outcome. It appears that there might be an issue with how I applied async a ...

Is there a way to automatically generate an HTML template within a .cshtml file using Visual Studio 2022?

During a recent ASP.NET project, I decided to create a new Details.cshtml file in Visual Studio 2022. My intention was to automatically generate an HTML template within the file, similar to the one shown below - <html xmlns=""http://www.w3.org ...

What is the best way for me to allow specific individuals to add text or strings to a .txt file stored on my server using PHP?

Imagine user1 types "Hello" in a text box and submits it, then later user2 writes "World" and submits it. How can I write code to send their inputs to my .txt file so that the file contains "Hello World"? This seems like a complex question to answer. If ...

Using React and Material-UI to dynamically populate a table with data retrieved from

Material ui table utilizes data in a specific format. rows: [ createData(1, "dashboard", "details"), createData(2, "product", "product details"), ].sort((a, b) => (a.id < b.id ? -1 : 1)) When the API responds with data stored in st ...

Can you recall the name given to characteristics that do not have any value assigned to them (e.g. "checked" and "selected")?

There is a specific group of attributes in HTML that do not accept a value. For example, the checked attribute for the <input> tag and the selected attribute for the <option> tag fall into this category. Do you know what term is used to refer ...

Encountering a 404 error for core.js and browser.js while loading an Angular 2 app through system.src.js

I am new to Angular2 and have followed the Angular2 quickstart and tutorial to get started. Just to provide some context, when a user clicks on a link in the top navigation bar of my webapp, it triggers a server side request. The resulting page returned t ...

Set a variable in MongoDB to retrieve the results of the find() method and convert them

Struggling to make this code function properly var data = db.collection('mycollection', function(er, collection) { return collection.find().toArray(); }); The variable data is not returning an array as expected. Uncle ...

Using Typescript with d3 Library in Power BI

Creating d3.axis() or any other d3 object in typescript for a Power BI custom visual and ensuring it displays on the screen - how can this be achieved? ...

Ensuring Consistency in Array Lengths of Two Props in a Functional Component using TypeScript

Is there a way to ensure that two separate arrays passed as props to a functional component in React have the same length using TypeScript, triggering an error if they do not match? For instance, when utilizing this component within other components, it sh ...

I am experiencing an issue where my React application is not loading the fonts when utilizing `type: 'asset/resource'` to load fonts within a CSS file. Can anyone provide guidance on

I'm encountering an issue with my webpack setup where fonts are not being loaded when using type: 'asset/resource'. Actually, there are several problems arising from the use of asset/resource, but let's focus on this particular issue fo ...

Issues with tabs functionality in Bootstrap version 4.3.1, unlike the smooth operation in v4.1.0

I encountered an interesting situation recently. After spending almost 3 hours troubleshooting my code, I discovered that it functions perfectly on Bootstrap v4.1.0 but fails on the latest version, v4.3.1. Working JSFiddle with Bootstrap v4.1.0: https://j ...

javascriptJQuery validation function triggers JSF ajax request

I am currently experiencing a challenge with JSF ajax requests and jQuery events. I am using a jQuery event to validate a section of a form like this: jQuery(".btnNextStep").live("click", function(e) { var error = !validate(id); ... ...

Increase the width of the div to extend it to the right side of the

After analyzing the issue, it seems like the solution lies in extending the wrapper div to the right side of the page without any wrapping. Whenever I attempt to set the width to 100vw or 100%, the content within the div gets pushed below all the other ele ...

Click to copy: Utilizing Italics in React Components

I've successfully implemented a way to copy text to the clipboard using React. Now, I'm facing the challenge of making only the content of this.state.parties italicized, while keeping the content of this.state.citation non-italicized when pasting ...

Avoiding content resizing when using a drawer in Material UI

My project features a drawer that expands, but I am encountering an issue where the content inside the drawer resizes when expanded. However, this is not the desired outcome. I want the expanded drawer to overlay the content without resizing it. How can I ...