antd按钮换行文字

问题描述

使用antd程序包(v3),我希望有一个固定宽度的按钮,该按钮在需要时会围绕其文本和换行符,以使文本适合按钮内部,并且边框会在文本周围正确显示。 / p>

这是我目前尝试的内容Codepen。我注意到使用空格:正常可与antd一起使用

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,);

解决方法

“ ant-btn” 类具有固定的height属性,您应该需要自动对其进行覆盖才能起作用。

<Button block type="primary" ghost style={{whiteSpace: "normal",height:'auto',marginBottom:'10px'}}>Wrap around text</Button>