antd 按钮自动换行

Kon*_*rad 5 html css antd

使用antd包(v3),我想要一个具有固定宽度的按钮,在需要时环绕其文本和换行符,以便文本适合按钮内部,并且边框正确显示在文本周围。

这是我目前尝试过的: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,
);
Run Code Online (Sandbox Code Playgroud)

小智 14

“ant-btn”类具有固定的高度属性,您应该需要通过自动覆盖它并且它可以工作。

<Button block type="primary" ghost style={{whiteSpace: "normal",height:'auto',marginBottom:'10px'}}>Wrap around text</Button>
Run Code Online (Sandbox Code Playgroud)