如何修复句子超出材料 UI 的框外。

huangapple go评论80阅读模式
英文:

How to fix the sentence going outside from the box material ui

问题

我正在使用Material UI。

我想把文本放在框内,但在想要响应式时,文本会超出框外。

注意:我已经尝试过Stack Overflow 的其他解决方案,如word-wrap、max-width、min-width,但都不起作用。

如何修复句子超出材料 UI 的框外。

代码如下:

<Stack direction={'row'} spacing={2}>
    <Box color={'rgb(24, 119, 242)'}><FacebookIcon /></Box>
    <Box
        sx={{
            '&:hover': {
                cursor: 'pointer',
                textDecoration: 'underline',
            },
        }}
    >
        <Link href="#" underline="none">
            https://www.facebook.com/caitlyn.kerluke
        </Link>
    </Box>
</Stack>
<Stack direction={'row'} spacing={2}>
    <Box color={'rgb(224, 45, 105)'}><InstagramIcon /></Box>
    <Box
        sx={{
            '&:hover': {
                cursor: 'pointer',
                textDecoration: 'underline',
            },
        }}
    >
        <Link href="#" underline="none">
            https://www.instagram.com/caitlyn.kerluke
        </Link>
    </Box>
</Stack>
<Stack direction={'row'} spacing={2}>
    <Box color={'rgb(0, 126, 187)'}><LinkedInIcon /></Box>
    <Box
        sx={{
            '&:hover': {
                cursor: 'pointer',
                textDecoration: 'underline',
            },
        }}
    >
        <Link href="#" underline="none">
            https://www.linkedin.com/in/caitlyn.kerluke
        </Link>
    </Box>
</Stack>
<Stack direction={'row'} spacing={2}>
    <Box color={'rgb(0, 170, 236)'}><TwitterIcon /></Box>
    <Box
        sx={{
            '&:hover': {
                cursor: 'pointer',
                textDecoration: 'underline',
            },
        }}
    >
        <Link href="#" underline="none">
            https://www.twitter.com/caitlyn.kerluke
        </Link>
    </Box>
</Stack>
英文:

I am using Material UI..

I want to place the texts inside the box but when want to make responsive ,the texts are going outside of thr box.

Note : I have already tried other solutions of stackover flow like word-wrap, max-width,min-width but did not work.

如何修复句子超出材料 UI 的框外。

code is,

&lt;Stack direction={&#39;row&#39;} spacing={2}&gt;
&lt;Box color={&#39;rgb(24, 119, 242)&#39;}&gt;&lt;FacebookIcon /&gt;&lt;/Box&gt;
&lt;Box
sx={{
&#39;&amp;:hover&#39;: {
cursor: &#39;pointer&#39;,
textDecoration: &#39;underline&#39;,
},
}}
&gt;
&lt;Link href=&quot;#&quot; underline=&quot;none&quot;&gt;
https://www.facebook.com/caitlyn.kerluke
&lt;/Link&gt;
&lt;/Box&gt;
&lt;/Stack&gt;
&lt;Stack direction={&#39;row&#39;} spacing={2}&gt;
&lt;Box color={&#39;rgb(224, 45, 105)&#39;}&gt;&lt;InstagramIcon /&gt;&lt;/Box&gt;
&lt;Box
sx={{
&#39;&amp;:hover&#39;: {
cursor: &#39;pointer&#39;,
textDecoration: &#39;underline&#39;,
},
}}
&gt;
&lt;Link href=&quot;#&quot; underline=&quot;none&quot;&gt;
https://www.instagram.com/caitlyn.kerluke
&lt;/Link&gt;
&lt;/Box&gt;
&lt;/Stack&gt;
&lt;Stack direction={&#39;row&#39;} spacing={2}&gt;
&lt;Box color={&#39;rgb(0, 126, 187)&#39;}&gt;&lt;LinkedInIcon /&gt;&lt;/Box&gt;
&lt;Box
sx={{
&#39;&amp;:hover&#39;: {
cursor: &#39;pointer&#39;,
textDecoration: &#39;underline&#39;,
},
}}
&gt;
&lt;Link href=&quot;#&quot; underline=&quot;none&quot;&gt;
https://www.linkedin.com/in/caitlyn.kerluke
&lt;/Link&gt;
&lt;/Box&gt;
&lt;/Stack&gt;
&lt;Stack direction={&#39;row&#39;} spacing={2}&gt;
&lt;Box color={&#39;rgb(0, 170, 236)&#39;}&gt;&lt;TwitterIcon /&gt;&lt;/Box&gt;
&lt;Box
sx={{
&#39;&amp;:hover&#39;: {
cursor: &#39;pointer&#39;,
textDecoration: &#39;underline&#39;,
},
}}
&gt;
&lt;Link href=&quot;#&quot; underline=&quot;none&quot;&gt;
https://www.twitter.com/caitlyn.kerluke
&lt;/Link&gt;
&lt;/Box&gt;
&lt;/Stack&gt;

答案1

得分: 1

你可以使用Text overflow CSS属性:

<Box
  sx={{
    "&:hover": {
      cursor: "pointer",
      textDecoration: "underline"
    },
    overflow: "hidden",
    textOverflow: "ellipsis"
  }}
>
  <Link href="#" underline="none">
    https://www.facebook.com/caitlyn.kerluke
  </Link>
</Box>

演示链接:https://codesandbox.io/s/elated-gauss-09yww7?file=/src/App.js

你可以在官方文档中了解更多信息:https://mui.com/system/display/#text-overflow

英文:

You can use the Text overflow css property:

 &lt;Box
sx={{
&quot;&amp;:hover&quot;: {
cursor: &quot;pointer&quot;,
textDecoration: &quot;underline&quot;
},
overflow: &quot;hidden&quot;,
textOverflow: &quot;ellipsis&quot;
}}
&gt;
&lt;Link href=&quot;#&quot; underline=&quot;none&quot;&gt;
https://www.facebook.com/caitlyn.kerluke
&lt;/Link&gt;
&lt;/Box&gt;

Live demo here: https://codesandbox.io/s/elated-gauss-09yww7?file=/src/App.js

You can read more about it on official doc: https://mui.com/system/display/#text-overflow

huangapple
  • 本文由 发表于 2023年1月9日 14:55:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75053995.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定