``Stylishly Designed CSS Tabs inspired by Google Chrome's Modern

Utilizing Material UI Tabs in React to create curved tabs resembling those seen in Google Chrome. The design requires the parent element to have a bottom border that extends across the entire row, appearing on both the tabs and other content on the right. However, the selected tab should not display this bottom border from its parent.

Expected Outcome:

Current Outcome:

The parent's border is mistakenly applied to the selected tab, contrary to what I intended. Take a look at my code on CodeSandbox link.

Approach Attempted:
I experimented with an ::after pseudo-element positioned absolutely for the selected tab, giving it a higher z-index. This pseudo-element was meant to cover the parent's bottom border with a white-colored horizontal line. However, my attempts were unsuccessful. Despite trying various CSS modifications, the parent's border would not budge. Any suggestions to refine my current approach or offer a new solution are welcome.

(Please keep in mind that I want to continue using Material UI Tabs as the foundation.)

Additionally, can anyone explain why there is a delay when selecting a tab?

Answer №1

If you're looking to achieve a specific effect, here's a solution: Remove the bottom border of the parent element, create a new CSS selector for giving tabs that are not .MuiSelected a bottom border, and add a bottom border to the someother content div so that the grey line extends across the entire page. You can adjust the shade of grey to match your color scheme:

Link to CodeSandbox

Subtabs

import styled from "@emotion/styled";
import MuiTabs from "@material-ui/core/Tabs";

export const StyledSubTabs = styled(MuiTabs)`
  .MuiButtonBase-root.MuiTab-root {
    background: white;
    border-radius: 8px 8px 0 0;

    :hover {
      background: pink;
    }
  }

  .MuiButtonBase-root.MuiTab-root.Mui-selected {
    border-top: 3px solid gray;
    border-left: 3px solid gray;
    border-right: 3px solid gray;
    border-bottom: none; /* not working */
    z-index: 10;

    :hover {
      background-color: pink;
    }
  }
//
//added this
//
  .MuiButtonBase-root.MuiTab-root {
    border-bottom: 3px solid gray;
    z-index: 10;

    :hover {
      background-color: pink;
    }
  }

  .MuiTabs-indicator {
    display: none;
  }
`;

App.js

import React, { useState } from "react";
import Tab from "@material-ui/core/Tab";
import { StyledSubTabs } from "./SubTabs.styles";

const App = () => {
  const [index, setIndex] = useState(0);
  const handleChange = (event, newIndex) => {
    console.log("SubTab - index", newIndex, event);
    setIndex(newIndex);
  };

  const parentStyles = {
    // remove this ---->  borderBottom: "3px solid gray",
    display: "flex",
    justifyContent: "space-between",
    alignItems: "center"
  };

  return (
    <div style={parentStyles}>
      <StyledSubTabs value={index} onChange={handleChange}>
        <Tab label="Tab 1" />
        <Tab label="Tab 2" />
        <Tab label="Tab 3" />
      </StyledSubTabs>
      <div
//added this
        style={{
          borderBottom: "3px solid gray",
          height: 45,
          flexGrow: 1
        }}
      >
        Some Other Content
      </div>
    </div>
  );
};

export default App;

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

Tips for confirming date is earlier than current date in Reactjs?

Looking for guidance on how to ensure a date selected by a user is always before the current date when using Material UI in my project. For instance, if it's January 6th, 2021 and the user selects either January 5th or 6th that would be acceptable. Ho ...

The Video Element Is Not Expanding to Fill the Entire Parent Div

My goal is to design a responsive layout where a video element spans the full width of its parent div with the class .hero. However, despite my best efforts, the video doesn't seem to be expanding as expected. Here's the relevant CSS code I' ...

Switching Text in ReactJS from V to X: A Tutorial

I have been utilizing a Switch component from react-switch in my project. import Switch from 'react-switch'; render() { return <Switch onChange={this.onChangeStatus} onClick={this.onChangeStatus} c ...

Techniques for animating background image using jQuery

Hello there! I'm currently experimenting with animating a background image using jQuery. Despite following a tutorial, I haven't been successful in getting my test page to work as intended. The blue Facebook icon displays, but it doesn't ani ...

Is there a solution available for tidying and organizing a CSS stylesheet efficiently?

In the project I am currently working on, the previous developers took an interesting approach by constructing all the selectors based on individual properties. For instance: .panel .selected a, a.selected-thumb, .date-picker input[type="submit"], .headi ...

Autocomplete feature is not functioning properly when trying to use JSON input

Currently, I am utilizing the MUI autocomplete component in my project. The situation involves making an API call and populating 'options' and 'value' with the response from the API. Below is the code snippet. // App.js import { useEff ...

Tips for decreasing the height and dimensions of a Material-UI<Select> input field within a Material UI and formik interface

I'm currently working on a web project utilizing React, Material, Formik, and formik-material-ui. The issue I'm facing is with the input screen of my form. The select input has a larger height compared to the textfield inputs. https://i.sstatic ...

How to Align the AppBar to the Left in MUI

Is there a way to position the AppBar on the left side of the screen using the React Material UI library from material-ui.com? I am working on a design that requires the global navigation to be displayed along the left side with a fixed position. Additiona ...

Personalizing the label of a select input using materialui

Working on customizing a select element using the "styled" method: const StyledSelect = styled(Select)` height: 2rem; color: #fff; border-color: #fff; & .${selectClasses.icon} { color: #fff; } & .${outlinedInputClasses.notchedOutl ...

Tips for enhancing the clarity of elements in KineticJS

I'm new to using Kinetic JS, and while I think it's a great library, I'm having trouble with the resolution of the elements. I know that Kinetic JS doesn't use SVG, but the resolution is not up to par. I'm creating circles and othe ...

Website Not Loading Correctly

Why is my webpage not loading properly, even though it has the same HTML and CSS as my other functioning pages on the site? The page loads without the h1 element. If I comment out the span used for adding a transparent background image behind the whole we ...

Replace !important with JavaScript/jQuery when using animate()

I need to animate the background-position-x, but there is a background-position: 0 0 !important; set in the css that cannot be removed. Is it possible to work around this using JavaScript? My jQuery code is functioning as intended, but it is being overridd ...

What is the best way to display DT elements next to each other?

Here is a link to the code snippet: http://jsfiddle.net/ZcdkT/1/ The code renders as: DT-nameA DD-definitionA 1 DT-nameB DD-definitionB 1 DD-definitionB 2 I would like it to be formatted like this: DT-nameA DT-nameB DD-definitionA 1 ...

The Bootstraps CSS style doesn't seem to be working properly or being overridden within an Angular

I have seen similar questions asked before, but none of the solutions provided have fixed my issue. It appears that the styles are being applied initially but then overridden by something else, and I am unable to identify what is causing this. The only r ...

php Use cURL and the DOM to extract content with specified CSS styling

Unclear in the title, I want to copy all content from a specific div on an existing webpage (not owned by me). The code successfully extracts the content. Extractor code: // Get Data $curl_handle=curl_init(); curl_setopt($c ...

Prevent the underlining of the :before content of a link from being affected by a rule applied to the link

I have a hyperlink that becomes underlined when hovered over. I want to add a > symbol before the link, but I don't want it to be underlined when the link is hovered. Here's the code I'm using: .box.blueb a { color: #0098aa; } .box.blueb ...

Material-UI tutorials: Tips for fixing the "Warning: Prop `id` did not match" issue

I'm currently working on a React app that displays a list of employees. However, I've encountered an issue with a console warning that says: Warning: Prop id did not match. Server: "undefined-Searchforanemployee-undefined-57040" Client: "u ...

The slider remains stationary, yet its value fluctuates

Below is the code snippet I have: class _ReadingBookPage extends State<ReadingBookPage> { double _sizeFont = 14; ... @override Widget build(BuildContext context) { return Scaffold( body: ... ...

Guide on aligning a non-fixed child within a fixed parent container

I am working on a project with a fixed container (div#popup) that has some CSS styling. The container is set to position:fixed, with specific dimensions, border radius, and background color. Within this fixed container, there is a form element that I am h ...

Custom background options for Wordpress developer

I have been exploring the WordPress codex to learn about incorporating custom background options, similar to this example $defaults = array( 'default-color' => '', 'default-image' => '&apo ...