html - 由于里面的内容,在 anchor 标签的帮助下填充按钮似乎宽度不一样

标签 html css responsive-design

我试图在 anchor 标记的帮助下创建一些按钮。我已经设置了每个标签的填充以获得按钮外观。但是,由于按钮内的内容似乎大小不一,即使我添加了 box-sizing 属性。

HTML

<ul>
<li class="list-pad"><a class="link-bg" href="{{link}}">{{location}}</a> </li>
</ul>

CSS

.link-bg
{
    width:2em;
    padding: 0.417em 0.833em;
    box-sizing: border-box;
    color: white;
    background-color: #007AFF;
    text-align: center;
    text-decoration: none;
    border-radius: 5px;
}

最佳答案

要使它们大小相同,您必须更改 anchor 标记的 display 属性。

.link-bg
{
    width:2em;
    padding: 0.417em 0.833em;
    display: block;
    box-sizing: border-box;
    color: white;
    background-color: #007AFF;
    text-align: center;
    text-decoration: none;
    border-radius: 5px;
}
<ul>
<li class="list-pad"><a class="link-bg" href="#">{{location}}</a> </li>
  <li class="list-pad"><a class="link-bg" href="#">{{location.location}}</a> </li>
</ul>

关于html - 由于里面的内容,在 anchor 标签的帮助下填充按钮似乎宽度不一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57221247/

相关文章:

html - 如何让2个绝对div居中

asp.net - 如何在单选按钮和单选按钮文本之间获得指定的空间?

html - 并排内联两个 div - CSS

jquery - Google Chrome 和 Firefox - div 的不同排序

jquery - 一个包含四个 div 页面的索引页面,而不是四个单独的 .html

html - 在移动 View 中隐藏 html 按钮

html - Spectre.css - 将 flexbox 拆分到另一行而不是缩小?

javascript - 使 slider 不超过视口(viewport)的高度

JavaScript Jquery 作业问题只适用于变量的最佳值

javascript - Python:如何将 python 脚本的输出作为 html 文件显示/重定向到浏览器上?