在元素中强制单行文本以使用CSS填充宽度 [英] Force single line of text in element to fill width with CSS

查看:245
本文介绍了在元素中强制单行文本以使用CSS填充宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div元素,其中包含一行文本。如何获取此文本以填充宽度100%?

I have a div element that holds one line of text. How can I get this text to fill the width 100%?

text-align:justify 元素与几行文本,并没有影响div与单行。手动调整字母间距和字间距是丑陋和无效的。是否有其他替代方案?

text-align:justify is only working on elements with several lines of text, and has no effect on the div with single line. Manually adjusting the letter-spacing and word-spacing is ugly and ineffective. Are there any other alternatives?

推荐答案

尝试:

div {
  text-align: justify;
}

div:after {
  content: "";
  display: inline-block;
  width: 100%;
}

jsFiddle

查看此处了解详情。

这篇关于在元素中强制单行文本以使用CSS填充宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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