A hover effect in CSS that utilizes a psuedo element to overlay the primary element

When hovering, I want to achieve an effect that looks similar to the display below:

To view my website, click here

The relevant code is shown below with the !important attributes removed:

    .cta-button-menu, .cta-button-menu::before {
        transition:all 0.3s linear;
        width: 120px;
        height: 50px;
        display: inline-flex;
        justify-content: center;
        align-items: center;
    }
    .cta-button-menu:hover {
        transform:rotateZ(-45deg);
        background: #21B6CD;
        color: white;
    }   
    .cta-button-menu::before {
        content:"Book Now";
        background-color:transparent;
        position:absolute;
        @include main-font($white, 16px, $font-bold);
      }
    .cta-button-menu:hover::before{
        transform: rotateZ(90deg);
        background-color:#e72f54;
        border:none;
    }

I'm having trouble getting the blue button to overlap the red:before button. Can't seem to figure it out.

Answer №1

Make a switch in the colors for .cta-button-menu:hover, change background: #e72f54 to background-color:#21B6CD. Also, adjust the rotation angles accordingly. Hopefully, these tweaks will work on your end.

ul {
margin-top: 60px;
}
.cta-button-menu,
    .cta-button-menu::before {
      transition: all 0.3s linear !important;
      width: 120px !important;
      height: 50px !important;
      display: inline-flex !important;
      justify-content: center !important;
      align-items: center !important;
    }

    .cta-button-menu:hover {
      transform: rotateZ(45deg) !important;
      background: #e72f54 !important;
      color: white !important;

    }

    .cta-button-menu::before {
      content: "Book Now" !important;
      background-color: transparent !important;
      position: absolute !important;
      @include main-font($white, 16px !important, $font-bold !important);
    }

    .cta-button-menu:hover::before {
      transform: rotateZ(-90deg) !important;
      background-color: #21B6CD !important;
      border: none !important;

    }
<ul>
<li class="cta-button-menu"><a class="mega-menu-link" tabindex="0">Book Now</a></li>
</ul>

Answer №2

To achieve this effect, you can utilize the power of CSS properties like transform and transform-style.

.cta-button-menu {
  transform-style: preserve-3d;
}

.cta-button-menu:hover::before {
  transform: rotateZ(90deg) translateZ(-1px);
}

Check out this CodePen example for a live demonstration.

Please note that this may not be supported in Internet Explorer 11.

Answer №3

Hey there @SinsiaM, after pondering a bit on your suggestion, I made some tweaks to the code:

    .cta-button-menu:hover {
        transform:rotateY(90deg) !important;
        background-color:#ff5733 !important;
        color: black !important;
    }   
    .cta-button-menu:hover::before{
        transform: rotateX(180deg) !important;
        background: #17E9C1 !important;
        z-index: 2;
        border:none !important;
    }

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

Positioning the jQuery mobile navBar to be fixed on iOS 4 devices

Currently working on a mobile app with jquery using iOS4 and iOS5 compatibility as the final hurdle. While fixing the navigation bar is simple on iOS5 with position:fixed, it's not as straightforward on iOS4! I've experimented with various soluti ...

The background image fails to load in ReactJS application

Usually, I have no trouble finding solutions to my problems, but this time I'm really stuck - and I apologize in advance if my question seems silly or trivial. I am currently working on a simple React app where I need to set a background image for th ...

Using JQuery to cycle a class with a timer

My list has the following structure <div id="slider"> <ul> <li class='active'> a </li> <li> b </li> <li> c </li> <li> d </li> <li> e </li> </u ...

Use the jQuery library to detect scrolling and toggle the CSS class between 'selected' and

I am trying to dynamically add the "selected" class to a[href] when a specific DIV comes into view while scrolling. However, I want to remove this class completely once the DIV has been scrolled past. const links = $(".cd-faq-categories li a"); // Find al ...

Ways to modify the CSS of an active class within a child component when clicking on another shared component in angular

In my HTML template, I am encountering an issue with two common components. When I click on the app-header link, its active class is applied. However, when I proceed to click on the side navbar's link, its active class also gets applied. I want to en ...

What is the best way to compress HTML code within a webpage's source?

I have noticed that my template is filled with empty spaces after previewing the page due to using many tags. Is there a way to make my code more compact, similar to the example below: https://i.sstatic.net/ZBlbg.jpg [...] startsWith",function(a){return ...

Rearrange HTML list items automatically according to changes in numeric sort order

I am working on a web page that features a dynamic ranked list. The items in the list are assigned a specific rank order number which changes based on user interactions elsewhere on the page. I have been exploring different options to automatically reorgan ...

Utilizing window.matchMedia in Javascript to retain user selections during page transitions

I am encountering difficulties with the prefers-color-scheme feature and the logic I am attempting to implement. Specifically, I have a toggle on my website that allows users to override their preferred color scheme (black or light mode). However, I am fac ...

Begin one lesson, end all others

Looking for help with my expandable list menu that I created using jQuery. Here is the code snippet: $("#menu ul li ul").hide(); $("#menu ul li").click(function() { $(this).find("ul").slideToggle(); }); You can view the fully functional menu on jsFi ...

Differences between PHP Filter and PHP htmlspecialchars compared to sqli prepare in PHP

I've been intrigued by the pros and cons of different methods for preventing SQL injection. The PHP filter checks if the input is in the correct format and returns true or false, which can then be sent to the server or not. Using the PHP htmlspecial ...

Browser behavior for animating background-position varies

check out this interactive demo - The objective is to create a unique perspective effect while scrolling, specifically on the background. The effect functions properly on Chrome and IE7, IE8 versions; however: Issues arise with IE9, where the background ...

displaying the information when we mouse over a specific row in the table

I need to display a pop-up with data from a table row, similar to the image at this URL for CS WHOLESALE GROCERS. I've implemented the following AngularJS code in my controller: app.directive('tooltip', function(){ return { res ...

Prevent the text within the textarea from wrapping onto the next line

My challenge involves a textarea where text overflows onto the next line when it exceeds the maximum characters. However, I want the text to continue on the same line with a scroll bar for better visibility. Here's an illustration: text here flows on ...

Tips on creating a script for detecting changes in the table element's rows and columns with the specified data values

I have a div-based drop-down with its value stored in TD[data-value]. I am looking to write a script that will trigger when the TD data-value changes. Here is the format of the TD: <td data-value="some-id"> <div class="dropdown">some elements& ...

Access a webpage whose URL has been dynamically assigned using JavaScript

I have a website that consists of a single page and features four tabs. Whenever a tab is clicked, it displays the corresponding content in a div while hiding the other three divs along with their respective content. To ensure a smooth user experience, I u ...

CrispyForms: FormHelper - Easily move the </form> tag to a different location and manage multiple forms from a single model

When utilizing FormHelper and invoking the Form using {% crispy form %}, it generates a Form wrapped within <form> tags. However, my Template is structured into two columns. The first column displays the dynamically generated {% crispy form %}. The ...

Creating custom designs for Material UI components

Although not a major issue, there is something that bothers me. I am currently using react, typescript, and css modules along with . The problem arises when styling material ui components as I find myself needing to use !important quite frequently. Is th ...

Maximizing Content Width in FullCalendar v5 to Ensure Screen Compatibility

As I develop a calendar and timeline view using fullcalendar v5, my clients are requesting a month view that displays the entire month without any scroll bars. While I am aware of setting the contentHeight to auto, there seems to be no option for adjusting ...

Cause a bootstrap column to have overflowing content rather than expanding

I've searched extensively for the solution to my problem, but haven't found a satisfactory answer yet. My goal is to create a location finder with a map on the right and a list on the left. With over 18,000 locations to search through, the list ...

What is the process for incorporating a button to the left of the search field?

Is it possible to enhance the search field by adding a button to make it more user-friendly? Below is the code I have been using: <div id="search"> <div class="container"> <h1>Search U.K. house price data</h1> <form c ...