css - 不同的<a href...=""> in a same size box</a>

时间:2013-02-14 10:08:25

标签: css

我的页面上有一些链接。这些链接由边框包围,并为它们设置背景。它们基本上都在一个盒子里。

<!DOCTYPE html>
<style>
a {
    background: #DDD;
    border: #BBB;
    padding:1px;
    width: 20em;    /*no effect*/
    height: 2em;    /*no effect*/
}
</style>
<a href="http://stackoverflow.com">1</a>
<a href="http://stackoverflow.com">1111111111111</a>

如何让这些盒子具有相同的尺寸?

1 个答案:

答案 0 :(得分:1)

不太了解但是如果你想要相同大小的包装器而不仅仅使用display: block;,因为<a>是一个内联元素,因此你需要使它成为块级元素,或者如果你想要块内联,只需使用display: inline-block;

<style>
a {
    background: #DDD;
    border: #BBB;
    padding:1px;
    width: 20em;
    height: 2em;
    display: block; <------ Add This
}
</style>