max-width调整以适合文本? [英] max-width adjusts to fit text?

查看:84
本文介绍了max-width调整以适合文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是最好的标题,但是无论如何...

Not the best title, but anyway...

我有一个带有max-width和一些文本的元素.

I have an element with a max-width and some text.

如果文本的长度超过一行的长度,我会得到以下提示:

If the text is longer than will fit on one line, I get this:

----------------------------
|My text here, hello       |
|everyone!                 |
----------------------------

换句话说,它占据了整个最大宽度,但是由于单词向下移动,因此右侧有一个空白空间.

In other words, it takes up the full max-width, but there's an empty space on the right due to the word moving down.

有没有办法做到这一点呢?

Is there any way to make it so that this happens instead?

---------------------
|My text here, hello|
|everyone!          |
---------------------

推荐答案

单独使用CSS不可能

根据此答案中的BoltClock ,这是不可能的.这种解释是有道理的.为了使换行开始,该行需要达到max-width设置.完成后,它会自动换行,但不会收缩,因为它使用该大小来计算自动换行.

Not Possible by CSS Alone

According to BoltClock in this answer, it is not possible. The explanation makes sense. For the line wrap to occur to begin with, the line needs to reach the max-width setting. Once done, it wraps, but it does not reshrink because it is using that size for the calculation of the wrap.

据我所知,这仍然是不可能的.

As far as I know, this is still not possible.

这篇关于max-width调整以适合文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆