文本对齐:证明不起作用
HTML
<div id="menu">
<a href="#">Commissions</a>
<a href="#">Business Setup</a>
<a href="#">Administrator</a>
<a href="#">Content Management</a>
<a href="#">Inventory</a>
<a href="#">Communications Tools</a>
<a href="#">Genealogy</a>
<a href="#">Reports</a>
</div>
CSS
#menu {
width: 1000px;
float: left;
font-size: 9pt;
text-align: justify;
}
#menu a {
text-decoration: none;
color: #0066cc;
font-size: 9pt;
}
#menu a:hover {
text-decoration: underline;
}
我想让每个链接都具有整个宽度。我尝试用 text-align: justify 来实现。但这不起作用。我该怎么做?
HTML
<div id="menu">
<a href="#">Commissions</a>
<a href="#">Business Setup</a>
<a href="#">Administrator</a>
<a href="#">Content Management</a>
<a href="#">Inventory</a>
<a href="#">Communications Tools</a>
<a href="#">Genealogy</a>
<a href="#">Reports</a>
</div>
CSS
#menu {
width: 1000px;
float: left;
font-size: 9pt;
text-align: justify;
}
#menu a {
text-decoration: none;
color: #0066cc;
font-size: 9pt;
}
#menu a:hover {
text-decoration: underline;
}
I want to make each links to have the whole width. I tried to implement so with text-align: justify. But it's not working. How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这将使 div 间隔均匀(可以是链接或任何元素)。您遇到的问题是 justify 不适用于单行文本(或最后一行文本)。这就是为什么您需要 :after psuedo 元素。
网页:
CSS:
This will make evenly spaced divs(can be links or about any element). The issue you ran in to is that justify doesn't work on a single line of text (or the last line of text). That is why you need the :after psuedo element.
Html:
Css:
我不确定我是否完全理解你的问题,但从你想要证明做一些它不是设计要做的事情的声音来看。
仅当一行文本在容器的右边缘换行时,文本才会对齐。
然而,这不可能真正发生在您的菜单中。
因此,我没有提出合理的修复(我说修复,尽管没有任何问题),而是提出了另一个建议。
根据我的理解,您希望链接均匀分布在您的 div 中。
我能想到的最好的方法是根据链接的数量为 a 元素提供基于百分比的宽度,并对齐到中心而不是对齐。
例如:
我不知道这是否是你想要的,但你可以尝试一下,看看你的想法。
I'm not sure if I completely understand your question, but by the sounds of things you want justify to do something that it was not designed to do.
Only when a line of text wraps at the right edge of a container will the text be justified.
This however, cannot really happen in your menu.
So instead of a justify fix (I say fix, although nothing is broken), I instead have another suggestion.
From my understanding you want your links evenly spread across your div.
The best way I can think of is to give the a elements a percentage based width based on the number of links and align to center instead of justify.
For example:
I don't know if it is what you want but you can try it and see what you think.
我只有一个表解决方案。 http://jsfiddle.net/Flack/Q7z6q/
我知道它很脏,如果有人的话我会很高兴有一个更好的主意。
I have only a tables solution. http://jsfiddle.net/Flack/Q7z6q/
I know it's dirty and will be glad if someone comes with a better idea.