html - 如何使用边框底部移动下划线以使其看起来像使用框阴影插图的下划线?
问题描述
简单的问题:
我可以使用border-bottom
(右侧的那些)使下划线看起来与使用box-shadow
(左侧的那些)完全一样吗?
我只需要它是 CSS。正如您从代码片段中看到的那样,它可能跨越多行。
基本上我需要将边框底部向上移动一点,而不是弄乱其他所有东西。
@import url('https://fonts.googleapis.com/css?family=Proxima+Nova');
div.flex {
display: flex;
width: 420px;
justify-content: space-between;
}
div.flex2 {
display: flex;
width: 300px;
justify-content: space-between;
}
h2 {
font-family: 'Proxima Nova';
color: rgb(60,128,124);
font-size: 21px;
font-weight: bold;
margin-top: 20px;
margin-bottom: 10px;
}
a.boxShadow {
color: darkGrey;
text-decoration: none;
line-height: 26px;
box-shadow: inset 0 -2px white, inset 0 -4px 0 rgb(60,128,124);
padding-bottom: 3px;
}
a.borderBottom {
color: darkGrey;
text-decoration: none;
line-height: 26px;
border-bottom: 2px solid rgb(60,128,124);
}
<div class="flex">
<h2>
<a class="boxShadow">Hello gjq box-shadow</a>
</h2>
<h2>
<a class="borderBottom">Hello border-bottom</a>
</h2>
</div>
<div class="flex2">
<h2>
<a class="boxShadow">Hello gjq box-shadow</a>
</h2>
<h2>
<a class="borderBottom">Hello border-bottom</a>
</h2>
</div>
这个问题的原因(浏览器一致性):
该box-shadow
示例完全符合我的要求,但在 Edge 上看起来不太好(而且我担心其他浏览器也可能无法正确呈现它)。不过,它在 Chrome、Firefox 和 Safari 的最新版本上看起来很完美。
在 Edge 上,box-shadow
示例如下所示(请参阅底部的小线泄漏):
另一方面,border-bottom
似乎在浏览器之间呈现一致。但我无法在我需要的位置获得下划线。
解决方案
渐变可以做到这一点
@import url('https://fonts.googleapis.com/css?family=Proxima+Nova');
div.flex {
display: flex;
width: 420px;
justify-content: space-between;
}
div.flex2 {
display: flex;
width: 300px;
justify-content: space-between;
}
h2 {
font-family: 'Proxima Nova';
color: rgb(60,128,124);
font-size: 21px;
font-weight: bold;
margin-top: 20px;
margin-bottom: 10px;
}
a.boxShadow {
color: darkGrey;
text-decoration: none;
line-height: 26px;
box-shadow: inset 0 -2px white, inset 0 -4px 0 rgb(60,128,124);
padding-bottom: 3px;
}
a.borderBottom {
color: darkGrey;
text-decoration: none;
line-height: 26px;
background:
linear-gradient(rgb(60,128,124),rgb(60,128,124))
bottom 1px center/ /* Position */
100% 2px /*width height*/
no-repeat;
}
<div class="flex">
<h2>
<a class="boxShadow">Hello gjq box-shadow</a>
</h2>
<h2>
<a class="borderBottom">Hello border-bottom</a>
</h2>
</div>
<div class="flex2">
<h2>
<a class="boxShadow">Hello gjq box-shadow</a>
</h2>
<h2>
<a class="borderBottom">Hello border-bottom</a>
</h2>
</div>
推荐阅读
- php - fopen(/vendor/dompdf/dompdf/lib/fonts/glyphicons-halflings-normal_c47afe5539ba1b2094563d54dce2def7.ufm):无法打开流:权限被拒绝
- arrays - 如何为猫鼬中的多个对象分配相同的ID?
- c++ - 如何将 std::find_if 与唯一指针向量一起使用?
- javascript - forEach() 不会更新数据库调用中的值
- huawei-mobile-services - 许多用户告诉我,我的应用程序的(安装)按钮在华为应用程序库中被禁用
- node.js - heroku ENOENT:上传时没有这样的文件或目录
- graphviz - graphviz基本标尺:数字定位
- javascript - 如何修复 chrome 扩展通知错误?
- node.js - 反应原生绝对被父母隐藏
- random - 数组长度范围内的 Ada 随机整数