css - 如何使用 CSS 向 h2 添加双边框底部?
问题描述
我想在 CSS 中为 h2 添加这种边框底部:
我在 CSS 中尝试了以下代码:
h2 {
font-size: 16px;
color: rgb(239, 112, 96);
border-bottom: 2px solid rgb(239, 112, 96);
padding-bottom: 5px;
}
h2::after {
content: "";
display: block;
border-bottom: 2px solid rgb(239, 112, 96);
width: 25%;
position: relative;
bottom: -9px; /* your padding + border-width */
}
以及markdown中的以下代码:
## Statistics Programs
我得到了一个几乎完美的结果。但是,厚底不会自动等于 h2 文本的长度。
那么,我是否可以单独修改 CSS 代码以获得理想的效果呢?
解决方案
您可以尝试如下:
h2 {
font-size:40px;
display:inline;
border-bottom:5px solid red;
}
h2::after {
content:"";
display:block;
border-top:3px solid red;
margin-top:4px;
}
<h2>A title here</h2>
<p> more text here</p>
也像这样:
h2 {
font-size:40px;
display:inline;
border-bottom:5px solid red;
}
h2 + hr {
border-top:3px solid red;
margin-top:4px;
}
<h2>A title here</h2>
<hr>
<p> more text here</p>
推荐阅读
- c# - 如何修复 Azure 构建管道错误:元素中的属性“版本”
无法识别 - javascript - javascript fetch 提取数据
- sql - 如何做 MAX COUNT 所以查询返回 1 个结果 SQL
- javascript - 类似问题如何修改 JS 和 PHP 代码
- javascript - 关于使用 React 上的钩子排队状态更改的问题
- python - 使用 Kubernetes Python 客户端加载 kubect 配置文件返回错误:无效的 kube-config 文件
- c++ - 替换字符串数组中所有出现的字母
- sql - 删除 BigQuery 上的数据
- python - 使用 S3 中的嵌套分区文件创建数据框,并在架构中加载具有分区列名称的数据框
- c# - IdentityServer4:登录回调返回 404 状态代码 - 未触发 UserInfo 端点