Transitioning from a CSS box-shadow effect to an inset-box shadow on hover

Have you ever encountered the challenge of transitioning from a normal box-shadow to an inset box-shadow? I'm curious if this is the reason why my transition isn't working, or if there's another issue with my code. What steps should I take if the transition doesn't seem to be functioning in this scenario?

Below is the snippet of the code in question:

.event_con > p:nth-of-type(1),
.event_con > p:nth-of-type(2){
    margin-top: 125px;
    width: 80px;
    height: 100px;
    border-radius: 25px;
    background: #f7f7f7;
    box-shadow: 3px 3px 18px #a5a5a5,
        -1px -1px 10px #e2e2e2;
    cursor:pointer;
    transition:all 0.4s;
}

.event_con > p:nth-of-type(1) {
    float: left;
    margin-right: 50px;
    position: relative;
}

.event_con > p:nth-of-type(1) img {
    position: absolute;
    left: 28px;
    top: 30px;
}

.event_con > p:nth-of-type(2) {
    float: right;
    position: relative;
}

.event_con > p:nth-of-type(2) img {
    position: absolute;
    right: 28px;
    top: 30px;
}


.event_con > p:nth-of-type(1):hover,
.event_con > p:nth-of-type(2):hover{
    background: #efefef;
    box-shadow: inset 5px 5px 10px #b5b5b5,
            inset -5px -5px 5px #ffffff;
}
<div class="event_con">
       <p><img src="https://via.placeholder.com/20x35" alt="pre" width="20" height="35"></p>
       <p><img src="https://via.placeholder.com/20x35" alt="next" width="20" height="35"></p>
</div><!--event_con-->

Answer №1

.content_block > div:nth-of-type(1),
.content_block > div:nth-of-type(2){
    margin-top: 125px;
    width: 80px;
    height: 100px;
    border-radius: 25px;
    background: #f7f7f7;
    box-shadow: 3px 3px 18px #a5a5a5,
        -1px -1px 10px #e2e2e2;
    cursor:pointer;
    transition:ease 0.4s all;
}

.content_block > div:nth-of-type(1) {
     float: left;
     margin-right: 50px;
     position: relative;
 }

.content_block > div:nth-of-type(1) img {
     position: absolute;
     left: 28px;
     top: 30px;
 }

.content_block > div:nth-of-type(2) {
     float: right;
     position: relative;
 }

.content_block > div:nth-of-type(2) img {
     position: absolute;
     right: 28px;
     top: 30px;
 }


.content_block > div:nth-of-type(1):hover,
.content_block > div:nth-of-type(2):hover{
     background: #efefef;
     box-shadow: 0px 0px 0px #a5a5a5,
     -1px -1px 10px #e2e2e2, inset 5px 5px 10px #b5b5b5,
             inset -5px -5px 5px #ffffff;
}
<div class="content_block">
       <div><img src="https://via.placeholder.com/20x35" alt="pre" width="20" height="35"></div>
       <div><img src="https://via.placeholder.com/20x35" alt="next" width="20" height="35"></div>
</div><!--content_block-->

We can implement a solution here by setting a 0px OUTER shadow on hover AND an inset shadow as needed.

If only the INSET shadow is provided, it will override the standard OUTER shadow in the CSS.

Hopefully, this explanation makes sense :D

Answer №2

It is true that transitioning from inset to normal is not possible.

However, a workaround is to have multiple box-shadows applied, as you are already doing.

One option is to transition your normal box-shadows to 0, while transitioning the inset ones to their desired value:

.event_con > p:nth-of-type(1),
.event_con > p:nth-of-type(2){
    margin-top: 125px;
    width: 80px;
    height: 100px;
    border-radius: 25px;
    background: #f7f7f7;
    box-shadow: 3px 3px 18px #a5a5a5,
              -1px -1px 10px #e2e2e2,
          inset 0px 0px 0px  #a5a5a5,
          inset 0px 0px 0px  #e2e2e2;
    cursor:pointer;
    transition:all 0.4s;
}

.event_con > p:nth-of-type(1) {
    float: left;
    margin-right: 50px;
    position: relative;
}

.event_con > p:nth-of-type(1) img {
    position: absolute;
    left: 28px;
    top: 30px;
}

.event_con > p:nth-of-type(2) {
    float: right;
    position: relative;
}

.event_con > p:nth-of-type(2) img {
    position: absolute;
    right: 28px;
    top: 30px;
}


.event_con > p:nth-of-type(1):hover,
.event_con > p:nth-of-type(2):hover{
    background: #efefef;
    box-shadow: 0px 0px 0px #b5b5b5,
                0px 0px 0px #ffffff,
         inset 5px 5px 10px #b5b5b5,
         inset -5px -5px 5px #ffffff;
}
<div class="event_con">
       <p><img src="https://via.placeholder.com/20x35" alt="pre" width="20" height="35"></p>
       <p><img src="https://via.placeholder.com/20x35" alt="next" width="20" height="35"></p>
</div><!--event_con-->

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

Plugin for creating a navigation bar with a jQuery and Outlook-inspired style

Our team is considering transitioning our asp.net forms application to MVC. Currently, we utilize outlook-style navigation with ASP controls such as listview and accordion, using code referenced here. Are there any jQuery/CSS controls available for MVC t ...

Use JavaScript to change the CSS pseudo-class from :hover to :active for touch devices

Looking to eliminate hover effects on touch devices? While it's recommended to use a hover class for hover effects, instead of the hover pseudo-class, for easier removal later on, it can be a challenge if your site is already coded. However, there&apo ...

What is the reason for adding CSS styles to a JavaScript file without importing them?

/Navbar.js/ import './navbar.scss'; import {FaBars, FaSearch} from "react-icons/fa"; import { useState } from 'react'; function Navbar(){ const [hide,sethide] = useState(true); const barIcon = document.querySelectorAl ...

Determine the amount of unused vertical space within a block of text

Having applied CSS to a span element: font-height = 120px; height = 120px; line-height = 120px; The text inside the span does not completely fill the height of 120px. Is there a method to determine the offset of the text from the top and bottom boundar ...

JavaScript and CSS animations out of sync in terms of timing

I've been encountering some issues. I have an array containing 5 lines of text that change with a timer, but it seems that the css timer animation might not be synced properly or my @keyframes slidesdown setup could be incorrect. The delay between te ...

Does the Parent Tag style override the child tag style when hovering?

I am currently dealing with some style issues. How can I apply the styling of the parent tag to the child tag when hovering over it? Let's illustrate this with a simple example. .outer:hover { background: yellow; z-index: 1; position: relativ ...

The appearance of a CSS select box may vary across different computers and web browsers

The appearance of a select box in HTML can vary between different computers and browsers. For example, on one computer using Google Chrome, the select box may look like this: https://i.stack.imgur.com/g2Xnn.png However, on my computer with Google Chrome, ...

Modify CSS to switch body background image when a DIV is hovered

Feeling a bit lost on where to start with this issue. My divs are positioned as desired on the page. Just to clarify, I am utilizing CSS Grids for this. In short, all I'm wondering is if it's possible to change the background of the body elemen ...

CSS gallery slideshow with images that smoothly fade-in and fade-out at a specified location

In the image below, at position 4 (marked by yellow circle) from the left where picture 6 is displayed, I want a cross-fade (fade-in/fade-out) gallery of images to take place. Specifically at position 4, I am looking for a cross-fade (fade-in/fade-out) ef ...

What could be causing my form to not be centered on the screen?

Currently working on creating a form for adding books to a fictional library website. The form tag is enclosed within a div, but despite the CSS styling applied, it remains fixed to the left side of the screen and I'm struggling to understand why. .fo ...

Creating an AI adversary for a simple Tic Tac Toe game board: a step-by-step guide

Being new to programming, I recently completed a basic Tic Tac Toe gameboard successfully. However, as I progress to the next phase of my assignment which involves implementing an AI opponent, I encountered several challenges. As a novice in programming, ...

Javascript and CSS combo for creating a stylish fade effect

Hey everyone, I have a design challenge where I need to change the color of a picture inside a box when the user hovers over it. I have four boxes like this and my goal is to make everything else fade out when a user hovers over a specific box. Anyone kn ...

Is there a way to keep a div element anchored at the top of the page until I reach the bottom and then have it stick to the bottom as I continue

I have a question that I hope is clear enough! On my webpage, there is a div at the top that I want to move to the bottom when I scroll and reach the end of the page. Hopefully, you understand what I'm trying to achieve! If anyone has any ideas, I&ap ...

How should I refer to this style of font?

After trying to implement a font from bulletproof @font-face as a template for my website, I am facing issues. My goal is to utilize the perspective-sans black regular font. Despite uploading the necessary files - including the css style sheet provided in ...

I need assistance in making my Gradient design compatible with different browsers

Currently, I am using this Gradient style: background: -moz-linear-gradient(center top , #FFFFFF 0px, #DDDDDD 100%) repeat scroll 0 0 transparent; However, I need a multi-browser compatible version of it. Can anyone help me with that? ...

Material UI categorizing iPads with a width of 768px and a height of 1024px as belonging to the small

I am facing a challenge with the layout of my app on different screen sizes. To address this issue, I am utilizing Material UI's breakpoints to control the layout based on the screen size. According to the documentation, screens categorized as small ...

Maintain the expanded menu even after selecting a sub-item using jQuery

After conducting a thorough search, I was unable to find exactly what I needed. I have successfully implemented cookies on my menu so that when the page is reloaded, it remembers which menus were open. However, I noticed that clicking on a sub-item of Hy ...

Adding text to a horizontal scrolling element causes the parent div to be pushed downwards

Can anyone help me understand why inserting text into one of the divs in a horizontally scrolling div causes the parent div to move downward? Looking for suggestions! @import url('https://fonts.googleapis.com/css?family=Hind:300,400,500,600,700&apo ...

The feature of option display is not supported on Safari browser

I am facing an issue with the functionality of two dropdown menus. The options in the second dropdown are supposed to be shown based on the selection made in the first dropdown. While this feature works perfectly in Chrome, it seems to be malfunctioning i ...

Is the HTML encoded character displaying strangely due to spacing issues?

I'm having trouble creating a link with a right chevron that has a larger font size. The issue I'm facing is that the right chevron appears to have excessive top margin, causing a significant gap between it and the line above. Additionally, I wa ...