html - 如何使 <a> 的填充高度为 <li>.table-cell 的 100%?

标签 html css

这道题是这样的:How to make an <a> 100% height of <li>? , 除了这次 a 元素需要垂直填充。这里:https://jsfiddle.net/7j60xgbg/是 fiddle 。在 a 上设置 height: 100%; 不起作用,因为它会延伸到列表下方。

如何使此 fiddle 中的所有 a 元素填充可用高度保留其填充?

最佳答案

box-sizing : border-box 是你的 friend :

a {
    display: block;
    background-color: green;
    color: black;
    padding: 0.5em 1em;
    height: 100%;
    box-sizing: border-box;
}

更新 fiddle https://jsfiddle.net/7j60xgbg/3/

关于html - 如何使 <a> 的填充高度为 <li>.table-cell 的 100%?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30501669/

相关文章:

jquery - 如何在 tbody 中选择所有具有特定背景颜色的 tr

javascript - 如何检查函数是否被调用

javascript - Accordion 切换图标

javascript - 将父 div 扩展到 TALLEST 绝对定位子项的高度

html - 仅在页面上显示内容

javascript - jQuery .click() 仅在加载时触发

html - 中心a :hover border and specify width of border

css - 如何在动态 react native 中设置默认样式和用户定义样式?

css - Asciidoctor render_file 缺少 CSS

javascript - jQuery 选择器和不同类型的 href 链接 - 为链接添加正确的 CSS 类