html - 右对齐段落中的溢出文本

标签 html css

我正在网络应用程序中处理诗歌,需要帮助解决对齐问题。

假设我正在处理以下通常左对齐的文本:

For now I know that all I lived and was
Moved towards this moment of my heart’s rebirth;
I look back on the meaning of myself,
A soul made ready on earth’s soil for thee.

随着浏览器窗口宽度的缩小(如在移动设备上),此文本可能会开始溢出到下一行,如下所示:

For now I know that all I lived and was
Moved towards this moment of my heart’s
rebirth;
I look back on the meaning of myself,
A soul made ready on earth’s soil for
thee.

但这不适用于诗歌。我真的很希望它显示为:

For now I know that all I lived and was
Moved towards this moment of my heart’s
                               rebirth;
I look back on the meaning of myself,
A soul made ready on earth’s soil for
                                  thee.

如何使用 CSS 实现这一点?

最佳答案

是的,....但不是。


是的,因为有一个 CSS 属性可以做到这一点:text-align-last

Per MDN

The text-align-last CSS property describes how the last line of a block or a line, right before a forced line break, is aligned

否,因为支持很差。它要么是实验性的(并且要求用户启用浏览器“标志”),要么根本不受支持。

只有 IE Edge 和 Chrome 实际上原生支持桌面浏览器。

CanIUse.com

.parent {
  width: 150px;
  border: 1px solid grey;
  margin: 1em auto;
  padding: 1em;
}
p {
  text-align: left;
  text-align-last: right;
}
<div class="parent">
  <p>I wandered lonely as a cloud</p>
</div>

关于html - 右对齐段落中的溢出文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34243059/

相关文章:

html - 为什么 flex box 从 2 列到 3 列和从 3 列到 4 列的工作方式不同?

javascript - 扩展搜索栏在搜索前不扩展

css - 空白被添加到 IE9 中的叠加层中,但 Fx5 中没有

javascript - 如何首先加载/呈现 HTML/CSS,然后再加载 Javascript(仅在必要时)?

html - (CSS) 具有动态调整大小图像的网格框布局

javascript - 如何触发布局改变?

html - 使用 Bootstrap 和 IE 修复垂直居中 div

html - 在哪里可以验证 Foundation 6 中的默认字体大小?

javascript - 同步多个YouTube视频

html - 简单的 css 仅在 anchor 上应用背景颜色