CSS 对齐 412px 中 5 个链接的宽度
我想要五个内联链接,其内边距大约为:5px 8px 5px 8px;固定边距为:0px 2px 0px 2px;在 412px 宽度的 div 内均匀分布内联
是一个示例: http://www.branklin.com /questions/css_justified_links.php
I want to have five inline links with an approximate padding of :5px 8px 5px 8px; and fixed margin of :0px 2px 0px 2px; evenly distributed inline within a 412px width div
here is an example: http://www.branklin.com/questions/css_justified_links.php
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我能得到的最接近的...您需要在链接周围添加另一个 div,否则它们不能在相对大小的同时具有填充/边距。 除非你的内边距和边距也是相对的%。
这里发生的情况是,
a
标签内的display:block;
导致它自动填充父标签,因此不需要宽度,并且填充和边距是自动调整为。请注意,float:left;
已移动到 div。当然,另一种方法是为链接设置固定宽度,同时考虑到填充、边距以及最大宽度,但最终会得到浮点像素值,这不太好。
This is the closest I could get it... You need to add another div around the links, or they can't have padding/margins at the same time as being relatively sized. Unless your padding and margins are also relative %.
What happens here is that the
display:block;
inside thea
-tag causes it to automatically fill the parent tag, so no width is needed, and the padding and margins are automatically adjusted for. Note that thefloat:left;
is moved to the divs.The alternative is of course to set a fixed width to the links, taking into account the padding and margins and the max width, but you'd end up with a floating point pixel value, which isn't so nice.
最简单的方法是使用显示属性(表格、表格行和表格单元格)。
示例:
css:
和 html:
the easiest way to do it with display property (table, table-row and table-cell).
example:
css:
and the html: