简体   繁体   English

CSS 边框折叠与 MUI 选项卡

[英]CSS border collapse with MUI tabs

在此处输入图像描述

In this picture #1 is the regular border which I need to have.在这张图片中,#1 是我需要的常规边框。 #2 and #3 are double the sizes of the #1. #2 和 #3 是 #1 的两倍。 In the #4 we can see it happens because both nearby elements have borders and those aren't collapsed.在#4 中,我们可以看到它的发生是因为附近的两个元素都有边框并且没有折叠。

In my React / MUI project I have added borderCollapse: "collapse" .在我的 React / MUI 项目中,我添加了borderCollapse: "collapse" But still, the problem is there.但是,问题仍然存在。

This is my code sandbox这是我的代码沙箱

What went wrong in my code?我的代码出了什么问题?

Each item in the Tabs gets it's own border that's why it looks double for the elements between.选项卡中的每个项目都有自己的边框,这就是为什么它之间的元素看起来是双倍的。

The closest solution with the less code I could find is to add negative margin-left in each item except the first one like the code below.我能找到的代码较少的最接近的解决方案是在每个项目中添加负margin-left ,除了第一个项目,如下面的代码。 Here is the working codesandbox这是工作代码和

    <Tabs
              value={value}
              onChange={handleChange}
              centered
              variant="fullWidth"
              aria-label="basic tabs example"
              sx={{
                ".MuiButtonBase-root": {
                  color: "white",
                  textTransform: "none",
                  borderCollapse: "collapse",
                  border: "1px solid #83858E",
                  fontWeight: "normal",
                  marginLeft: "-1px" // You add negative margin
                },
                "& :first-child": {
                  borderTopLeftRadius: "0.5rem",
                  borderBottomLeftRadius: "0.5rem",
                  margin: "0" // You remove the negative margin-left for the first element.
                },
                "& :last-child": {
                  borderTopRightRadius: "0.5rem",
                  borderBottomRightRadius: "0.5rem"
                },
                "& .MuiTabs-indicator": {
                  display: "none"
                },
                "& .MuiTab-root.Mui-selected": {
                  color: "black",
                  backgroundColor: "#ABA9FF",
                  border: "1px solid white"
                }
              }}
            >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM