Shifting shadow transition effect when hovering over the box

I'm attempting to create a slide animation effect with box-shadow over an image, where the black background moves from left to right. However, I am facing a strange blinking issue that I can't seem to resolve even after searching for solutions on Stack Overflow.

I also experimented with using a section element instead of an image, but encountered the same problem.

You can view the JSFiddle demo here

HTML

<section>
</section>

CSS

section {
  border:black 1px solid;
  width:500px;
  height:200px;
  transition:1s ease-out
}

section:hover{
  box-shadow:inset 500px 0 0 #222;
  float:left;
  transition:1s ease-out;
}

Answer №1

Here is an alternative approach using a straightforward pseudo element technique and applying transition effects to the width property by adjusting its right position:

section {
      border: black 1px solid;
      width: 500px;
      height: 200px;
      position:relative;
      color:#c2c2c2;
      text-align:center;
      padding-top:50px;
      box-sizing:border-box;
    }

    section:before {
      position: absolute;
      content: " ";
      top: 0;
      bottom: 0;
      left: 0;
      background: #000;
      right: 100%;
      transition:1s ease-out;
      z-index:-1;
    }
    section:hover::before {
      right:0;
    }
<section>
      add your text here
    </section>

Answer №2

An alternative approach is to introduce a subtle box shadow effect in the initial state with a minimal spread radius.

  div {
      box-shadow: inset 0 0 0 0.001px black;
  }

Answer №3

It seems like the issue is related to how the box-shadow property works. Consider trying a different method. Here's an alternative solution that eliminates flickering by increasing the thickness of the left border instead of using box-shadow:

div {
  position: relative;
  display: inline-block;
}
section {
  border: black 1px solid;
  width: 500px;
  height: 200px;
  transition: 1s ease-out;
  box-sizing: border-box;
}

div:hover section {
  border-left-width: 500px;
  float: left;
  transition: 1s ease-out;
}

section~* {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  color: #888;
}
<div class="prog">
  <section></section>
  <p>Here's some text content.</p>
</div>

https://jsfiddle.net/k5kznmvL/

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

CSS not working when attempting to override Angular (13) Material file

In my Angular (13) application with Material, I have developed a CSS file specifically for overriding certain Material styles. This CSS file is imported into the styles.scss file as the last line. However, despite importing the external file, the CSS def ...

Using the "margin: auto" property to center the text box

I am having trouble centering the search box. I tried adding marginLeft: "auto",marginRight: "auto" to the search class but it's not working. Can you please advise me on how to fix this issue? Below is my code snippet and a link to the sandbox: https ...

The bottom of the page displays varying outcomes between Code Snippet (CodePen) and Angular

I had the idea of having my footer cover the entire length of the page and stick to the bottom, adjusting itself if more content is added. However, I encountered an issue where on Codepen everything works perfectly, but on Angular (14), the footer does not ...

The design of the Bootstrap alert button is not working properly as it fails to close when clicked on

While experimenting with Bootstrap, I encountered an issue with the bootstrap alert button that seems to be malfunctioning. I simply copied the code from Bootstrap's official website: https://i.sstatic.net/DRLIg.png However, upon testing it on my pag ...

arrangement of columns within the <select> element

I have been attempting to create a column layout inside of <select> using CSS, but so far I have been unsuccessful. https://i.sstatic.net/ltIDl.png This is the HTML code I have tried: <select id="select-bill-period"> <option>Select ...

Ways to conceal a dynamically generated div upon page load?

I am currently facing a scenario where I need to dynamically create a div. My initial approach was to create it on the document ready event, but the requirement is for it to be displayed only upon selection. The problem I am encountering is that the empty ...

CSS issue: Font size

Can someone help me out with a CSS issue that has been tripping me up? I've been working with CSS for three years now, and this particular problem is stumping me. I have defined some styles in my CSS file that should be applied to the content of my w ...

How can I create a more spacious and stylish JTextField for my address bar?

I am working on developing my Java skills by creating a custom browser. Is there a way to adjust the size and shape of the address bar, which is currently implemented as a JTextField with Swing's default settings? Here is the code snippet I am using: ...

In the Bootstrap grid, the first two rows are tightly packed with no empty space between them

Currently working on coding a footer with a grid/table using Bootstrap 4. However, encountering an issue where there's no spacing between the first and second rows in the grid. Oddly enough, there is spacing between all other columns. Can anyone provi ...

Discover the hidden content within a div by hovering over it

Here is an example of a div: <div style="width:500px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis pulvinar dui. Nulla ut metus molestie, dignissim metus et, tinc ...

CSS - fixed table headers

Check out my CodePen example here - Code In this demo, I have a table inside a container where the table is larger than the container. As you scroll horizontally, both the table and headers move accordingly. However, when scrolling vertically, I want th ...

What is the best way to make floating images fill the entire space?

I'm looking to create a grid layout with fixed-sized images, but I'm having trouble getting them to fill up the space properly. Here's what I want: Unfortunately, this is what I'm currently getting: Any suggestions on how I can make t ...

Employ CSS to target the initial and final items within sets of identical elements

I created the following CSS styles: div { width: 300px; text-align: center; } p:not(.vrt) { text-align: left; } p.vrt { writing-mode: vertical-rl; display: inline-block; } div :nth-child(1 of p.vrt) { margin-left: 0; } div :nth-last-child(1 of ...

What is the best way to rearrange columns in bootstrapping version 3

In the process of developing a responsive website with the use of bootstrap 3, I am faced with the task of rearranging columns for the mobile version. The layout of the home page has been attached for reference, along with the desired layout for the mobi ...

Deciphering image coordinates provided for incorporating an animated image component into a form

Is there a way to store the X:Y coordinates of a user click on an animated image by examining the php $_POST array? My issue is that I am able to retrieve input submission data from static images, but not from the animated one. Below is the full HTML page ...

Position footer at the bottom of the webpage and adjust the height to be filled with main content using Bootstrap 4

I am currently in the process of designing a bootstrap layout that includes a header navbar along with a footer. My goal is to ensure that the footer is always at the bottom of the page, even if there is limited content. Here's what I have implemente ...

Unable to adjust the color of the font

I am trying to create a toggle effect for the colors of a fontawesome icon when clicking on a text link, but it only works with a button. Here is the HTML code snippet: <div class='post'> <i class='fas fa-heart' id='h ...

What is the process for adding personalized arrows to a slick slider that switches images when hovered over?

I'm currently utilizing the slick slider from . My goal is to have my custom arrows change appearance when hovered over. Below you will find the JavaScript code I've implemented to customize the left and right arrows within the slider. However, ...

What steps can I take to update the header and footer of my website?

Hey there! Just wanted to share that my website, newinternetdaily.com, recently got a fresh look with the installation of the newsmag cracked theme. However, I'm facing an issue with changing the default text in the header section since I don't k ...

JavaScript Animation: Enhancing TextBox Borders

I'm exploring an idea for a loading animation, but I'm feeling a bit lost on where to begin. Basically, I have a text box that gets populated automatically with JavaScript on the page, however, it takes some time to load. I want to create somethi ...