"Enhance Your Design: Creative CSS Animation Effects for Underlined

I've been experimenting with incorporating animation into material-UI, specifically making the underline move from left to right for a tab. Here's the code I've come up with:

const useStyles = makeStyles({
link: {
    padding: "1rem",
    color: "black",
    fontSize: "18px",
    fontWeight: "400",
    lineHeight: "24px",
    position: "relative",

    "&:before": {
      content: "''",
      position: "absolute",
      width: "0",
      height: "2px",
      bottom: "0",
      left: "0",
      backgroundColor: "#FFF",
      visibility: "hidden",
      transition: "all 0.3s ease-in-out",
    },
    "&:before:hover": {
      visibility: "visible",
      width: "100%"
    }
  }
}

function Tab(props) {
  const classes = useStyles();
  const {href} = props;
  const preventDefault = (event) => event.preventDefault();
  return (

    <Link href={href} onClick={preventDefault} className={classes.link}>
      <Typography variant="h6">{props.children}</Typography>
    </Link>
  );
}

Upon testing this code, the tab is behaving differently than expected and not displaying the intended animation.

To guide my implementation, I'm referring to this source.

Answer №1

.example{
  color:blue;
  position:relative;
  display:inline-block;
}
.example::before{
      content: "";
      position: absolute;
      width: 0;
      height: 2px;
      bottom: 0;
      left: 0;
      background-color: purple;
      visibility: "hidden";
      transition: all 0.3s ease-in-out;
    
}
.example:hover::before{
  visibility: visible;
      width: 100%;
}
<div class="example">
hover over me
</div>

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

Interested in leveraging string functions on the information retrieved from the API?

I am trying to utilize String functions such as slice(x,y), length() on the data received from the API. To achieve this, I first converted the data to a variable called mystr using JSON.stringify(obj), but encountered an issue where the console displayed: ...

Implement the maskmoney library in your input fields

In the form below, I am automatically adding inputs using a JavaScript function like this: $('.Preco1').maskMoney({ decimal: '.', thousands: ' ', precision: 2 }); $('.Preco1').focus(); $('#sub').maskMon ...

What is the functionality of custom npm scripts in my codebase?

Currently, I am delving into node js code and came across an interesting piece of information in the package.json file. The script that caught my attention looks like this: scripts: { start : 'some-dependency start' } When I execute npm run ...

What is the process for updating the input type in mbrn/material-table during inline editing?

Recently in MUIv5, there has been a change in the default variant of the textfield, causing issues with styling within the input field when in edit mode. The new variant includes excessive padding and margins, taking up too much space. Despite attempting ...

implementing datepicker on multiple textboxes in jQuery upon button click

I have the ability to show multiple text boxes using jQuery. I am now looking to add a datepicker to those text boxes. Any assistance in finding a solution would be greatly appreciated. Thank you in advance. ...

execute the code when the device is not an iPad

if ( (navigator.userAgent.indexOf('/iPadi') != -1) ) { } This conditional statement is used to identify whether the user's device is an iPad, but I specifically want to execute the code only if it is not an iPad. I have a JQuery hover func ...

Updating a React state using a matrix in a simple yet effective way

I'm struggling with figuring out how to save input values from the table generated by the code below: createTable = () => { let table = []; for (let i=0; i<this.state.rows; i++) { let rowID = `r${i}`; let cell = []; for (let j=0; j<this ...

The transition feature is not functioning properly in Firefox

I have a basic HTML and CSS setup below. It seems to be working fine in Chrome, but I'm having trouble with the transition effect in Firefox. I am currently using Firefox version 18. I tried looking up solutions on Google and Stack Overflow, but none ...

"Skip the inbox clutter and access the compose page directly on Gmail, Yahoo, and

I was looking to create a unique hyperlink that would direct users to a compose page similar to Google Mail. Here is an example of what I tried: <li><a href="https://inbox.google.com/mail/?view=cm&fs=1&<a href="/cdn-cgi/l/email-protect ...

Using functions as properties in React.js

I am facing an issue while trying to pass a function as a prop. Although I have done this successfully in the past, now I am getting an error (this.props.functionName is not a function). I have a child component called Navbar and a parent component named ...

Ways to prevent a div containing a lengthy content string from extending beyond other divs

Check out my Codepen project here Here is the HTML code for my personal website: <div id="splash" class="divider"> <h1 class="text-center text-uppercase">vincent/rodomista</h1> <p class="text-center text uppercase">Full Stack ...

How can you utilize CSS to automatically generate section numbers, specifically for multiple sections?

Is it possible to automatically generate section numbering in CSS only when there are multiple sections present? I discovered that using CSS, one can create automatic numbering for sections. body { counter-reset: section } h2 { counter-reset: sub-section ...

Why can't the file upload button locate its CSS styles?

Check out this jFiddle demonstrating the issue. Some of the Angular code may appear broken in the example, but that's just due to it being pasted into jFiddle; it's not an actual problem I'm facing. The CSS styles aren't working on the ...

Inquiry about CSS3 transitions

Exploring the world of transitions in webkit. Currently experimenting with transitioning the dimensions of a div on hover and observed that the width is animated from the top and left of the div....but ideally, I want it to expand from the center of the ...

The jsPdf library performs well on medium-sized screens like laptops, but when downloaded from larger monitor screens, the PDF files do not appear properly aligned

In the code snippet below, I am using html2canvas to convert HTML to PDF. The PDF download works fine on medium screens, but when viewed on larger screens, some pages appear blank and the content order gets shuffled. How can I resolve this issue so that th ...

What is the best way to retrieve the ID of the cell that is currently being focused on in the MUI Data Grid?

With the MUI Data Grid, users have the ability to click on a cell to bring it into focus, navigate through cells using keyboard arrows, and manually set the focused cell. One thing that I'm struggling with is determining which cell is currently in fo ...

Best practices for working with HTML elements using JavaScript

What is the best approach for manipulating HTML controls? One way is to create HTML elements dynamically: var select = document.getElementById("MyList"); var options = ["1", "2", "3", "4", "5"]; for (var i = 0; i < options.length; i++) { var opt = ...

Jekyll adjusting the starting line of code snippet formatting

Currently, I'm in the process of setting up code highlighting for my blog using Jekyll and Pygments. However, I'm facing an issue where the first line of every code snippet seems to be slightly offset. To create a gutter effect, I'm utilizin ...

Managing data flow in React and Reflux: Utilizing a single component duplicated in the DOM

Imagine this Tree scenario: <Homepage> <HeaderSection> <Navbar> <ShoppingCartComponent> </Navbar> </HeaderSection> <MainContent> <ShoppingCartComponent> &l ...

An alternative for the ReactPlayer component in Vue JS

In my previous projects, I relied on the ReactPlayer component. Now I'm curious if there is a similar option available for Vuejs? I stumbled upon this alternative, but it appears to be abandoned and lacks some features compared to ReactPlayer. ...