前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CSS3标题文本后的横线

CSS3标题文本后的横线

作者头像
itclanCoder
发布2023-09-14 17:15:43
1670
发布2023-09-14 17:15:43
举报
文章被收录于专栏:itclanCoderitclanCoder

示例代码

代码语言:javascript
复制
<template>
   <div>
        <h2 class="background">删除线</h2>
        <h2 class="background"><span>左右两侧线</span></h2>
        <h2 class="background double"><span>双层线</span></h2>
        <h2 class="no-background"><span>左右两侧线</span></h2>
        <h2 class="no-span">左右两侧线</h2> 
   </div>
</template>
<style scoped>
h2 {
    font: 33px sans-serif;
    margin-top: 30px;
    text-align: center;
    text-transform: uppercase;
}
h2.background {
    position: relative;
    z-index: 1;
}
h2.background:before {
    border-top: 2px solid #dfdfdf;
    content: "";
    margin: 0 auto;
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    bottom: 0;
    width: 95%;
    z-index: -1;
}
h2.background span {
    background: #fff;
    padding: 0 15px;
}
h2.double:before {
    border-top: none;
}
h2.double:after {
    border-bottom: 1px solid blue;
    -webkit-box-shadow: 0 1px 0 0 red;
    -moz-box-shadow: 0 1px 0 0 red;
    box-shadow: 0 1px 0 0 red;
    content: "";
    /* this centers the line to the full width specified */
    margin: 0 auto;
    position: absolute;
    top: 45%;
    left: 0;
    right: 0;
    width: 95%;
    z-index: -1;
}
h2.no-background {
    position: relative;
    overflow: hidden;
}
h2.no-background span {
    display: inline-block;
    vertical-align: baseline;
    zoom: 1;
    *display: inline;
    *vertical-align: auto;
    position: relative;
    padding: 0 20px;
}
h2.no-background span:before,
h2.no-background span:after {
    content: '';
    display: block;
    width: 1000px;
    position: absolute;
    top: 0.73em;
    border-top: 1px solid red;
}
h2.no-background span:before {
    right: 100%;
}
h2.no-background span:after {
    left: 100%;
}
h2.no-span {
    display: table;
    white-space: nowrap;
}
h2.no-span:before,
h2.no-span:after {
    border-top: 1px solid green;
    content: '';
    display: table-cell;
    position: relative;
    top: 0.5em;
    width: 45%;
}
h2.no-span:before {
    right: 1.5%;
}
h2.no-span:after {
    left: 1.5%;
}
</style>
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2023-08-05 00:00,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 itclanCoder 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档