簡體   English   中英

CSS 邊框折疊與 MUI 選項卡

[英]CSS border collapse with MUI tabs

在此處輸入圖像描述

在這張圖片中,#1 是我需要的常規邊框。 #2 和 #3 是 #1 的兩倍。 在#4 中,我們可以看到它的發生是因為附近的兩個元素都有邊框並且沒有折疊。

在我的 React / MUI 項目中,我添加了borderCollapse: "collapse" 但是,問題仍然存在。

這是我的代碼沙箱

我的代碼出了什么問題?

選項卡中的每個項目都有自己的邊框,這就是為什么它之間的元素看起來是雙倍的。

我能找到的代碼較少的最接近的解決方案是在每個項目中添加負margin-left ,除了第一個項目,如下面的代碼。 這是工作代碼和

    <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