CSS 属性 text-align-last  描述的是一段文本中最后一行在被强制换行之前的对齐规则。

/* Keyword values */
text-align-last: auto;
text-align-last: start;
text-align-last: end;
text-align-last: left;
text-align-last: right;
text-align-last: center;
text-align-last: justify;

/* Global values */
text-align-last: inherit;
text-align-last: initial;
text-align-last: unset;
初始值auto
适用元素block containers
是否是继承属性yes
适用媒体visual
计算值as specified
Animation typediscrete
正规顺序the unique non-ambiguous order defined by the formal grammar

语法

属性值

auto
每一行的对齐规则由 text-align 的值来确定,当 text-align 的值是 justifytext-align-last 的表现和设置了 start 的表现是一样的,即如果文本的展示方向是从左到右,则最后一行左侧对齐与内容盒子。

译者注:
经测试,当 text-align 的值为 right,并且 text-align-last 设置为 auto 时,文本最后一行的对齐方式相当于 text-align-last 被设置为 right 时的效果。即 text-align-last 设置为 auto 后的表现跟 text-align 的设置有关。

start
direction 的设置有关。
如果文本展示方向是从左到右,起点在左侧,则是左对齐;
如果文本展示方向是从右到左,起点在右侧,则是右对齐。
如果没有设置 direction ,则按照浏览器文本的默认显示方向来确定。
end
direction 的设置有关。
如果文本展示方向是从左到右,末尾在右侧,则是右对齐;
如果文本展示方向是从右到左,末尾在左侧,则是左对齐。
如果没有设置 direction ,则按照浏览器文本的默认显示方向来确定。
left
最后一行文字与内容盒子的左侧对齐
right
最后一行文字与内容盒子的右侧对齐
center
最后一行文字与内容盒子居中对齐
justify
最后一行文字的开头语内容盒子的左侧对齐,末尾与右侧对齐。

语法

auto | start | end | left | right | center | justify

示例

p {
  font-size: 1.4em;
  text-align: justify;
  -moz-text-align-last: center;
  text-align-last: center;
}

规范

规范 状态 备注
CSS Text Module Level 3
text-align-last
Working Draft Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic support
Experimental
Chrome Full support 47
Full support 47
No support 35 — 47
Disabled
Disabled From version 35 until version 47 (exclusive): this feature is behind the Enable Experimental Web Platform Features preference (needs to be set to true). To change preferences in Chrome, visit chrome://flags.
Edge Full support 12Firefox Full support 49
Full support 49
No support 12 — 53
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
IE Partial support Partial
Notes
Partial support Partial
Notes
Notes IE only supports text-align-last when text-align is set to justify.
Notes The start and end values are not supported.
Opera Full support YesSafari No support No
Notes
No support No
Notes
Notes See WebKit bug 76173.
WebView Android Full support 47
Full support 47
No support 37 — 47
Disabled
Disabled From version 37 until version 47 (exclusive): this feature is behind the Enable Experimental Web Platform Features preference (needs to be set to true).
Chrome Android Full support 47
Full support 47
No support 35 — 47
Disabled
Disabled From version 35 until version 47 (exclusive): this feature is behind the Enable Experimental Web Platform Features preference (needs to be set to true). To change preferences in Chrome, visit chrome://flags.
Edge Mobile Full support YesFirefox Android Full support 49
Full support 49
No support 14 — 53
Prefixed
Prefixed Implemented with the vendor prefix: -moz-
Opera Android Full support YesSafari iOS No support No
Notes
No support No
Notes
Notes See WebKit bug 76173.
Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
Partial support  
Partial support
No support  
No support
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

参见

文档标签和贡献者

标签: 
此页面的贡献者: Miss-violet
最后编辑者: Miss-violet,