亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

React - Material UI Typography 如何將長字符串分成多行

React - Material UI Typography 如何將長字符串分成多行

偶然的你 2022-05-14 15:16:17
我正在使用 ReactJS 和名為 MaterialUI 的組件庫。我在使用 Typography 組件時遇到問題。發生的情況是,如果我寫一個長文本,它會超出其容器并且不會換行:import React from "react";import { Redirect } from "react-router";import { withRouter } from "react-router-dom";import Container from "@material-ui/core/Container";import CssBaseline from "@material-ui/core/CssBaseline";import Typography from "@material-ui/core/Typography";function Homepage() {  return (    <div>      <React.Fragment>        <CssBaseline />        <Container fixed>          <Typography variant="h1" component="h2" align="center">            123 456 789 qwertyuiopasdfghjklzxcvbnm          </Typography>        </Container>      </React.Fragment>    </div>  );}export default withRouter(Homepage);在圖像下方:這發生在移動模式和桌面模式中。你知道如何解決這種行為嗎?如果已達到容器的最大寬度,我希望將長單詞拆分為新行。
查看完整描述

3 回答

?
慕尼黑8549860

TA貢獻1818條經驗 獲得超11個贊

解決方案


使用word-wrap,它適用于 Material-UI 的排版。


wordWrap: "break-word"


演示


<Typography

  variant="h1"

  component="h2"

  align="center"

  style={{ wordWrap: "break-word" }}

>

  123 456 789 qwertyuiopasdfghjklzxcvbnmdfsafasfasfadfaf

</Typography>


查看完整回答
反對 回復 2022-05-14
?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

我遇到了這個,這是一個很好的解決方案。我最終將它全局添加到我的排版中。如果您需要這個,只需將 keikai 的答案添加到您的 createMuiTheme。


//theme.jsx or theme.tsx

import { createMuiTheme, responsiveFontSizes } from '@material-ui/core/styles';



let theme = createMuiTheme({

  overrides: { 

    MuiTypography: { 

      root: { 

        wordWrap: "break-word"

      }

   } 

  }

});


export default theme;


查看完整回答
反對 回復 2022-05-14
?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

更新 24-11-2021 createMuiTheme 已棄用有效的新版本:


const theme = createTheme({

    components: {

        MuiTypography: {

            styleOverrides: {

                root: {

                    wordWrap: "break-word"

                },

            },

        },

        MuiCard: {

            styleOverrides: {

                root: {

                    width: "auto",

                    margin: 10,


                },

            },

        },

    },

});


查看完整回答
反對 回復 2022-05-14
  • 3 回答
  • 0 關注
  • 256 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號