[英]React - vertically align text and icon
I have tried all things to align vertically an icon and a text, Code:我已经尝试了所有方法来垂直对齐图标和文本,代码:
<Danger color="secondary" style={{ flex:1,justifyContent: "center",alignItems: "center" }}>
<ErrorOutline
className={classes.warning}
/>
<text numberOfLines={1} style={{ textAlignVertical: "center" }}>
The last job was canceled
</text>
</Danger>
Things that I've tried : display, justifyContent, alignItems, flex, flexDirection, etc.
我尝试过的东西: display, justifyContent, alignItems, flex, flexDirection, etc.
Any advice?有什么建议吗? Thanks!谢谢!
Try out this inside render of react code在 react 代码的渲染中试试这个
<div style={{display: 'flex', lineHeight: '40px'}}>
<img src="https://png.icons8.com/ios/50/000000/user-male-circle-filled.png" height="40"/>
<div>Welcome User!!!</div>
</div>
And for clear understanding you can find the entire React code for this particular example in this link: https://jsfiddle.net/r6yLmu8t/为了清楚地理解,您可以在此链接中找到此特定示例的整个 React 代码: https : //jsfiddle.net/r6yLmu8t/
You need to give lineHeight for the div tag in which the image/icon and text are there.您需要为图像/图标和文本所在的 div 标签提供 lineHeight。 And make sure that the icon/image height is equal to the lineHeight given to the div.并确保图标/图像高度等于赋予 div 的 lineHeight。
Hope this will achieve your need of text and icon to be on the same line and text to be at centre of icon/image希望这将实现您需要的文本和图标在同一行和文本在图标/图像的中心
<Button light>
<View style={{flexGrow: 1, justifyContent:'center', alignItems: 'center'}}>
<Icon name='arrow-back' />
<Text>Back</Text>
</View>
</Button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.