[英]Strange behaviour involving Closure commands and “text-align:justify”
I have some divs within a Soy template that I want to be evenly spaced, horizontally. 我在Soy模板中有一些div,我希望它们在水平方向上均匀分布。
Here is what does work: 这是起作用的:
CSS (nomenclature simplified for this example): CSS(此示例简化了术语):
.list-of-things {
position: relative;
text-align: justify;
}
.list-of-things::after {
display: inline-block;
width: 100%;
content: '';
}
.list-of-things div {
display: inline-block;
height: 25px;
weight: 25px;
}
The ::after rule just adds a fake last line, since justify won't apply to the last line. :: after规则仅添加了伪造的最后一行,因为证明将不适用于最后一行。
HTML (in the soy template): HTML(在大豆模板中):
<div class="list-of-things">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
Ta-da! - This is what it looks like (border solidity added, to make it clearer):
外观如下所示(添加了边框实体,使其更加清晰):
JSFiddle demonstrating this: http://jsfiddle.net/ULQwf/1257/ JSFiddle对此进行了演示: http : //jsfiddle.net/ULQwf/1257/
Here is the problem: 这是问题所在:
If I stick the divs inside any Closure commands (if, for, etc.), like this: 如果我将div插入任何Closure命令(如果,for等)中,则如下所示:
{if true}
<div>a</div>
<div>b</div>
<div>c</div>
{/if}
a, b, c divs will all just fall to default inline-block behaviour, on the left. a,b,c div都将落在左侧的默认内联块行为中。 Looks like this:
看起来像这样:
Even weirder, if I lump everything together, like this: 甚至更奇怪,如果我将所有内容都放在一起,就像这样:
<div class="list-of-things">
{if true}
<div>a</div>
<div>b</div>
<div>c</div>
{/if}
<div>1</div>
<div>2</div>
<div>3</div>
</div>
a, b, c divs will continue to default to the left. a,b,c div将继续默认为左侧。 In the remaining space in the inline row, 1, 2, 3 divs will be nicely justified:
在内联行的剩余空间中,1、2、3 divs将是合理的:
If I reverse the order and put the regular divs first and then Closure divs second, then the result is very similar, but a, b, c will be lumped together on the right instead of the left. 如果我颠倒顺序,然后将常规div放在第一位,然后将Closure divs放在第二位,则结果非常相似,但是a,b,c将集中在右侧而不是左侧。
Looking through Developer Tools on Chrome, each div -- a, b, c, 1, 2, 3 -- looks exactly the same. 浏览Chrome上的开发人员工具,每个div(a,b,c,1、2、3)看起来完全一样。 Same computed values.
计算值相同。
Another point -- all other text-align values work. 另一点-所有其他文本对齐值都起作用。 If I change justify to text-align:center, all six divs will sit nicely together in the center.
如果我将justify更改为text-align:center,则所有六个div都将很好地放在中间。 Same for text-align:left/right/etc..
相同于text-align:left / right / etc。
Is there something about how templates and justify are computed/compiled that I'm not understanding? 关于模板和证明的计算/编译,我不了解吗? Do closure commands produce some sort of secret hidden surrounding div?
闭包命令会在div周围产生某种秘密吗?
Discoveries: 发现:
Basically, this doesn't work: 基本上,这不起作用:
<div>
{if true}
<div>a</div>
<div>b</div>
<div>c</div>
{/if}
</div>
But this does! 但是,确实如此!
<div>
{if true}
<div>a</div>{sp}
<div>b</div>{sp}
<div>c</div>{sp}
{/if}
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.