简体   繁体   English

React 图标与文本不对齐

[英]React icon does not align with text

I have a very simple question, I have react icon and text in front of it.我有一个非常简单的问题,我在它前面有反应图标和文字。 The text is not aligned with the React Icon.文本未与 React 图标对齐。 How can I align it with text?如何将其与文本对齐? Check the screenshot.检查屏幕截图。 My code is:我的代码是:

<MdPerson size={20}/><span> Profile</span>

screenshot截图

Try to wrap icon component and your span label with outer div block.尝试用外部div块包装图标组件和您的span标签。 Then apply some class to the div where child elements aligned by flexbox.然后将一些类应用于 div,其中子元素由 flexbox 对齐。

.centered-label {
  display: flex;
  align-items: center;
}

Andriis answer of wrapping it in a flex box combined with the answer from this github issue thread worked for me. Andriis 将它包装在一个 flex 盒中的答案与来自这个 github 问题线程的答案相结合对我有用。

vertical-align: bottom; style on the icon.图标上的样式。

As suggested by Andrii, wrap your Icon component & span label in a parent div style the div as below:按照 Andrii 的建议,将您的 Icon 组件和span标签包装在父div样式中,如下所示:

<div style={{display: "flex", justifyContent: "center"}}>
<MdPerson size={20}/><span> Profile</span>
</div>

Worked for me perfectly!完美地为我工作!

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

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