html - seems `border-box` not working with inline-block of `a` tag
问题描述
I am trying to integrate the box-sizing
but seems not working. any one help me to understand the issue here..
a{
display:inline-block;
background:#fff;
border:1px solid #ccc;
box-sizing:border-box;
padding:1rem;
}
a.active{
border:0;
background:orange;
}
<a class="active" href="#">EN</a><a href="#">FR</a>
解决方案
代码中有两个主要问题:首先,正如@Daniel 在他的回答中指出的那样,元素的尺寸必须明确,以防止自动调整大小。此外,如this answer中所述,inline-block
元素与border-box
大小冲突,但有几种解决方法。
一方面,CSS 属性overflow: hidden
也可以添加到相关元素中。或者,可以使用vertical-align: top
以确保所有元素具有相同的基线。下面可以看到一个功能示例,用更大的边框来强调:
a{
display:inline-block;
background:#fff;
border:10px solid #ccc;
box-sizing:border-box;
width:5em;
height:5em;
overflow:hidden;
padding:1rem;
}
a.active{
border:0;
background:orange;
}
<a class="active" href="#">EN</a><a href="#">FR</a>
推荐阅读
- r - R中的类权重和案例权重之间的区别?
- boost - 如何解决缺少 boost-python 包的问题?
- javascript - 具有多个索引打字稿的对象到数组
- python - 图嵌入虚拟数据集
- flutter - Flutter 聊天气泡
- regex - Webpack SVGO-Loader 中的逆正则表达式匹配
- r - 当我编织我的文件时,我收到“第 6 行错误 .... 找不到函数 %>%”消息
- google-apps-script - Google Apps 脚本 - 例外
- javascript - chrome 扩展和 Azure 文本分析 API 之间的连接
- python - Python - 如何仅对选定的行和列范围执行 log2 规范化