【发布时间】:2014-02-11 22:59:36
【问题描述】:
因为我很确定这是XY Problem 的一个实例,所以我将从Y 开始。我有一个 300 像素宽的图像,我想要图像下方的三个链接,与它齐平。最后一个链接需要增大大小以填充剩余空间。
现在是 X。我的标记在 Chrome 和 Firefox 中完美运行,但在 IE 和 Safari 中,第三个链接太大了 2px。
为了您的复制/粘贴乐趣:
<head>
<style type="text/css">
.breakfast
{
text-transform: uppercase;
padding: 10px 25px;
margin: 5px -5px;
font-family: Arial, Sans-Serif;
font-size: 14px;
font-weight: bold;
background-color: #d9e021;
color: #00add0;
text-align: center;
text-decoration: none;
display: inline-block;
}
.breakfast:hover
{
text-decoration: none;
background-color: #bdc400;
color: #0198b6;
}
</style>
</head>
<body>
<div>
<img src="my_awesome_image.jpg" width="300"
height="190" alt="My awesome image." />
</div>
<div style="margin-left: 5px; margin-top: -5px;">
<a class="breakfast" href="#">BOSTON </a>
<a class="breakfast" href="#">CHICAGO </a>
<a class="breakfast" href="#" style="width: 38px;">DC </a>
</div>
</body>
或jsFiddle,由Mr.Lister 慷慨提供。
所以最后一个链接,“DC”在 Safari 和 IE 中超出图像 2px。如果我剃掉 2px,它在 Chrome 和 Firefox 中太短了。我还尝试在链接的左侧和右侧添加填充,但同样处理。
【问题讨论】:
标签: html css cross-browser padding