简体   繁体   English

text-align:justify不起作用

[英]text-align:justify not working

I've been successfully using the method described here (link to article) for the past few days. 在过去的几天中,我已经成功地使用了此处描述的方法(链接到文章)

It shows how to avoid calculating percentage-based margins for blocks in a grid by applying text-align:justify to the parent container. 它显示了如何通过将text-align:justify应用于父容器来避免为网格中的块计算基于百分比的边距。

An :after psuedo element makes sure there is always "text" being forced onto the next line to make sure it justifies. :after psuedo元素可确保始终在下一行强制插入“文本”以确保其合理性。

But in this particular instance (link to jsFiddle) the blocks are not responding to text-align: justify. 但是在这种特定情况下(链接到jsFiddle),这些块没有响应text-align:justify。 The code below has been working fine elsewhere so there's something I'm missing. 下面的代码在其他地方运行良好,所以我缺少一些东西。

HTML 的HTML

<div class="container"><div class="contents"></div><div class="contents"></div><div class="contents"></div><div class="contents"></div><div class="contents"></div></div>

CSS 的CSS

.container {
     font-size: 0.1px;
     text-align:justify;
}

.container:after {
    content: '';
    display: inline-block;
    width: 100%;
}

.contents {
    display: inline-block;
    vertical-align: top;
    width: 100px;
    height: 100px;
    border: 1px solid black;
}

text-align:justify works by stretching the spaces between the words, as delimited by space characters. text-align:justify通过扩展单词之间的空格(由空格字符分隔)来工作。 So, in order for the gaps between the inline-blocks to stretch, there must be space characters between them. 因此,为了扩大内联块之间的间隙,它们之间必须有空格字符。 In your example case, the blocks have no spaces between them. 在您的示例情况下,块之间没有空格。

Add the spaces, and the blocks will justify. 添加空格,这些块将对齐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM