标题两边的装饰符号

2022-03-24  本文已影响0人  何必再健

这是一个小demo,希望举一反三

第一种

HTML

<span class="title_h2">默认标题</span>

CSS

.title_h2{
    display: inline-block;
    position: relative;
    box-sizing: border-box;
    text-align: center;
    padding:5px 10px;
    margin: 0 auto;
    font-size: 16px;
    font-weight: bold;
    line-height: 20px;
}

.title_h2::before{
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    width: 10px;
    height: 10px;
    content: " ";
    border-top:2px solid #000;
    border-left:2px solid #000;
    transform: rotate(-5deg);
}
.title_h2::after{
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 0;
    width: 10px;
    height: 10px;
    content: " ";
    border-bottom:2px solid #000;
    border-right:2px solid #000;
    transform: rotate(5deg);
}

第二种

HTML

<span class="title_h3"><i></i>默认标题<i></i></span>

CSS

.title_h3{
    display: inline-block;
    text-align: center;
    margin: 0 auto;
    font-size: 16px;
    font-weight: bold;
    line-height: 20px;
}
.title_h3 i:first-child{
    position: relative;
    box-sizing: border-box;
    width:6px;
    height: 20px;
    display: inline-block;
}
.title_h3 i:first-child::before{
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    width: 10px;
    height: 10px;
    content: " ";
    border-top:2px solid #000;
    transform: rotate(-10deg);
}
.title_h3 i:first-child::after{
    position: absolute;
    top: 2px;
    left: -2px;
    z-index: 0;
    width: 10px;
    height: 10px;
    content: " ";
    border-left:2px solid #000;
    transform: rotate(10deg);
}
.title_h3 i:last-child{
    margin-top: 8px;
    float: right;
    position: relative;
    box-sizing: border-box;
    width:4px;
    height: 20px;
    display: inline-block;
}
.title_h3 i:last-child::before{
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 0;
    width: 10px;
    height: 10px;
    content: " ";
    border-bottom:2px solid #000;
    transform: rotate(-10deg);
}
.title_h3 i:last-child::after{
    position: absolute;
    bottom: 2px;
    right: -2px;
    z-index: 0;
    width: 10px;
    height: 10px;
    content: " ";
    border-right:2px solid #000;
    transform: rotate(10deg);
}
上一篇 下一篇

猜你喜欢

热点阅读