Ant Design v3 如何解决固定宽度Button文本换行样式失效问题
Antd v3 固定宽度按钮文本换行失效问题
实现需求
开发时需要实现固定宽度的按钮效果:
- 按钮宽度固定,文本内容超出宽度时可自动换行适配
- 文本换行后,按钮边框完整包裹全部内容,无文本溢出边框的情况
调试对比结果
- 给原生
<button>标签设置whiteSpace: normal样式,可正常实现换行与边框包裹效果 - 将完全相同的
whiteSpace: normal样式通过内联方式传入antd v3的Button组件时,换行效果无法生效
测试用代码
const { Button } = antd; ReactDOM.render( <> <div style={{ width: "100px" }}> <Button block type="primary" ghost style={{ whiteSpace: "normal" }}> Wrap around text </Button> </div> <button style={{ width: "100px", whiteSpace: "normal" }} type="primary"> Wrap around text </button> </>, mountNode );
内容的提问来源于stack exchange,提问作者Konrad
相关产品推荐
相关产品推荐

