简体   繁体   English

如何使用 css 使边框与按钮完全一致

[英]How to make border exactly with button using css

My objective is align border perfectly to the icons (the line of the border should start with delete icon and end with archived icon without containing any up and space in between the border)我的目标是使边框与图标完美对齐(边框线应以删除图标开头,以存档图标结尾,边框之间不包含任何向上和空格)

I've tried in this way:我试过这种方式:

 <div style={{ border: "1px solid black" }}>
      <DeleteIcon />
      <span>Hello</span>
      <ArchiveIcon />
    </div>


But still i could see some small space on the top of the icon and bottom too for border and icon .但我仍然可以在图标顶部和底部看到一些小空间用于边框和图标 Can anyone help me this query?谁能帮我这个查询?

Here is the working one: ( https://codesandbox.io/s/keen-chandrasekhar-gpjuh )这是工作的:( https://codesandbox.io/s/keen-chandrasekhar-gpjuh

There are many solutions but this should get the job done for you.有很多解决方案,但这应该可以为您完成工作。 Use flex box and specify height.使用弹性框并指定高度。 Check the solution below.检查下面的解决方案。

<div style={{ border: "1px solid black", height: "1rem" , display:"flex", alignItems: "center"
 <div style={{ border: "1px solid black", lineHeight: "24px" }}>

and

<style>
.MuiSvgIcon-root {
  vertical-align: middle;
}
</style>

should do the trick.应该做的伎俩。

Currently, the icons are placed on the base line (the invisible line, where letters are aligned to).目前,图标放置在基线上(不可见的线,字母对齐的位置)。 The two changes set (a) the height of the base line so that the text is centered between the icons and (b) the icons exactly in the middle of the resulting box.这两个更改设置 (a) 基线的高度,以便文本在图标之间居中,以及 (b) 图标正好位于结果框的中间。

Try this:试试这个:

<div
  style={{
    border: "1px solid black",
    display: "flex",
    alignItems: "center",
    width: "fit-content"
  }}
>

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

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