Sliding Tab Animation using solely CSS on Flexbox

I've been challenged with developing my own React Tabs component that includes a sliding animation, similar to what you see in mui or ant design.

I can achieve this using JavaScript, however, the limitation is that I cannot use CSS within JavaScript or inline CSS. Therefore, it must be purely SCSS / CSS in a Next.js project. Another complication is that the tabs need to be responsive (without fixed width), so the container is set to flex and can contain multiple tab items with varying widths. This makes it challenging to determine the item's width using pure CSS alone.

Is it feasible to create such an animation without relying on any JavaScript?

Answer №1

I am here to assist you.

It seems like you need to develop a separate functional component called Tabs.

You can specify the appropriate styles in each component.

1. Approach involving styling as components:

Here is an example of how you can define styles using styled components:

import styled from 'styled-components'

const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

const Wrapper = styled.section`
  padding: 4em;
  background: papayawhip;
`;

export default function Example(){

  return(
    <div>
      <Wrapper>
        <Title>
          Hello World!
        </Title>
      </Wrapper>
    </div>
  )
}

Refer to the documentation on how to use styled-components effectively.

2. Second Option: basic CSS styling

You can create a global.css file to store all your CSS styles, as outlined here.

3. Explore various examples of Tab sliders available online. (For instance, you can refer to this)

If you are considering a "pure css project", keep in mind that NextJS will transform all your pages into either .js or .tsx; hence, you cannot solely use pure HTML and CSS without transformation into .js.

Attempting to avoid using .js within a JavaScript/TypeScript framework may lead to issues, as different browsers have their own interpretation of CSS properties. You can refer to this table for more information.

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

Storing a boolean value in MongoDB as a string

const myObject = { school: true, address: false }; const myArray = []; myArray.push(myObject); updateSchool(myArray); function updateSchool(thisSchool) { $.ajax ({ type: "POST", url: '/update_school', d ...

What is the best way to determine the number of connections in Redis when using Node.js?

Is it possible to retrieve the number of current connections to the Redis database using Node.js? const redis = require('redis'); var client = redis.createClient(port, host); client.on('connect', () => { //Retrieve and display th ...

Try implementing a dynamic id to modify the background when hovering over the menu in the DAWN THEME

I have successfully created an editable section in the customizer where you can upload desktop and mobile images, as well as modify the menu. My current dilemma is how to associate these background images with each "Details-id" and have them change when a ...

In this JavaScript tool for counting characters, every carriage return is counted as two characters

Hello there! I have created a character counter in JavaScript that looks like this: <textarea class="SmsText" id="txttemplate" maxlength="160" /> <span id="charsCount">160</span></strong><span>character(s) left</span> ...

I am endeavoring to send out multiple data requests using a function, ensuring that the code execution occurs only once all the results have been received

After reading through a post on Stack Overflow about handling multiple AJAX calls in a loop (How to take an action when all ajax calls in each loop success?), I was able to come up with a solution. I decided to track the number of requests I needed to make ...

Using CSS to center the text and adding a separator line in blank spaces for a clean and stylish look

Request to Create Centered Date Element with Line Borders I am looking to design an element where the date is positioned at the center, while two horizontal lines fill the empty space on either side. Ideal Design I Want to Achieve: My Current Approach a ...

Attempting to implement a feature that will enable a blank row at the end of an input table with the help of

I'm currently working on a form that allows users to click a button to add a blank row to the bottom of a table. The issue I'm facing is that when I click the button, it redirects back to my index.php page instead of simply adding the row to the ...

Angular JS basic API: Displaying only information that starts with the term 'request'

I've been given the task of developing a straightforward AngularJS API. I have managed to set up the basics for displaying data, but I'm facing an issue where the table only retrieves data from the JSON file if it starts with "request". As a resu ...

Unable to find custom components when using react-router

My goal is to improve the organization of my Routes in React and separate concerns. I am currently utilizing react-router-dom version 5. Within my Application Routes component, I have structured it with 3 children components: AuthenticatedRoutes PublicRo ...

Which is causing the block: the event loop or the CPU?

example: exports.products = (req, res) => { let el = 1; for (let i = 0; i < 100000000000000; i++) { el += i; } console.log(el); ... ... ... res.redirect('/'); }; If I include a loop like this in my code, which resour ...

Encountering a problem involving the apostrophe character "'" when trying to save content into a MySQL database

I have been developing an application that allows users to create HTML templates and save them. Users can utilize different components such as text, images, etc. to build HTML pages. Challenge: The issue I'm encountering is when a user inputs text wi ...

Events are causing the Three.js canvas to resize

Currently, I am developing a mobile-web application using three.js. I have incorporated the meta viewport tag as well: <meta name="viewport" content="width=device-width; user-scalable=no; initial-scale:1.0; minimum-scale=1.0; maximum-scale=1.0;" > ...

The Label in Material UI TextField is appearing on top of the border,

Incorporating Material UI TextField and Material UI Tab, I have encountered an issue. There are two tabs, each containing a text field. Upon clicking on the TextField, the label's border is supposed to open, but this behavior only occurs if the curren ...

The Hover Hover textbox stays in place once clicked on

I have implemented a search bar that displays a textbox when a user hovers over a button. I am looking to modify the code so that the textbox remains visible even after the user has clicked on it. This way, if the user accidentally moves their mouse away f ...

Experimenting with a loader component in AngularJS

This is a test for a $resource with a loader describe('Service: MultiCalculationsLoader', function(){ beforeEach(module('clientApp')); var MultiCalculationLoader, mockBackend, calculation; beforeEach(inject(function (_ ...

What are the steps for transitioning with JavaScript?

My goal is to make both the <hr> elements transition, but I'm struggling with only being able to select the lower <hr> using CSS. html { margin-bottom: 0; height: 100%; min-height: 100%; } body { margin-top: 0; height: 100%; ...

Deactivate click events in the container div

Here is the html code snippet that I am working with: <div class="parent" ng-click="ParentClick()"> . . . <div class="child" ng-click="ChildClick()"> Some Text </div> </div> When clicking on Som ...

How can you force a line break on an inline-block element with CSS, after a specific number of elements?

I'm struggling to arrange a list of divs in a grid layout using only CSS, but I can't seem to make it work properly. I've explored using white-space: wrap, but that's supposed to be applied to the parent element, so it doesn't solv ...

What are the best ways to incorporate EMs and percentages into responsive web design?

As I delve into the world of responsive design, I am eager to understand the most effective practices when it comes to utilizing em and percentage units of measurement. In a scenario where I set the font-size of the body to 10px, could this potentially le ...

Tips for sending multiple values as a unified object using Javascript and Ajax

Currently, I am new to javascript and MVC. I am developing a sample application with a sign-up page where I am using ajax for the process. The code snippet below shows my current implementation: function create() { var user_name = $("#txtUser").val(); ...