这种效果在代码中可能吗?
Is this effect possible in code?
我注意到设计师遵循一个有趣的趋势来创建一种下划线,我很好奇这是否可以在代码中实现。它就像一个下划线,但它在单词后面。
为了获得最佳实践,您应该分享您的代码。从图片和问题来看,可以这样实现。
* {
box-sizing: border-box;
}
.heading {
color: #404C64;
font-weight: 700;
position: relative;
display: inline-block;
margin: 0;
padding-left: 10px;
padding-right: 10px;
line-height: 0.4;
}
.heading:after {
display: block;
width: 100%;
padding: 10px;
content: '';
position: absolute;
left: 0;
right: 0;
top: 100%;
background: #D9EEC3;
border-radius: 10px;
z-index: -1;
}
<h1 class="heading">Text here</h1>
<h1>Text Here</h1>
CSS:
h1 {
display: inline-block;
position: relative;
/* Adjust below values accordingly */
padding: 0 15px;
}
h1:after {
content: '';
display: block;
position: absolute;
z-index: -1;
width: 100%;
left: 0;
/* Adjust below values accordingly */
height: 20px;
margin-top: -15px;
background-color: lightgreen;
border-radius: 10px;
}
可以用更短的方式完成:
.underline {
font-size: 50px;
border-radius: 10px;
height: 10px;
width: 255px;
box-shadow: 0 45px 0 5px #D9EEC3;
font-family: sans-serif;
}
我注意到设计师遵循一个有趣的趋势来创建一种下划线,我很好奇这是否可以在代码中实现。它就像一个下划线,但它在单词后面。
为了获得最佳实践,您应该分享您的代码。从图片和问题来看,可以这样实现。
* {
box-sizing: border-box;
}
.heading {
color: #404C64;
font-weight: 700;
position: relative;
display: inline-block;
margin: 0;
padding-left: 10px;
padding-right: 10px;
line-height: 0.4;
}
.heading:after {
display: block;
width: 100%;
padding: 10px;
content: '';
position: absolute;
left: 0;
right: 0;
top: 100%;
background: #D9EEC3;
border-radius: 10px;
z-index: -1;
}
<h1 class="heading">Text here</h1>
<h1>Text Here</h1>
CSS:
h1 {
display: inline-block;
position: relative;
/* Adjust below values accordingly */
padding: 0 15px;
}
h1:after {
content: '';
display: block;
position: absolute;
z-index: -1;
width: 100%;
left: 0;
/* Adjust below values accordingly */
height: 20px;
margin-top: -15px;
background-color: lightgreen;
border-radius: 10px;
}
可以用更短的方式完成:
.underline {
font-size: 50px;
border-radius: 10px;
height: 10px;
width: 255px;
box-shadow: 0 45px 0 5px #D9EEC3;
font-family: sans-serif;
}