Dotted top and bottom border shorter than text

后端 未结 3 1786
野性不改
野性不改 2021-01-02 06:06

I want to achieve border top and bottom like below image how can I achieve with CSS tricks?

\"Image\"

Chall

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 06:44

    I made a few changes in your CSS:

    h1{
        text-align: center;
        font-size: 70px;
    }
    
    h1:before, h1:after{
        position: relative;
        content: "";
        width: 30%;
        left: 35%;
        display: block;
        margin-bottom: 10px;
        margin-top: 10px;
        border-bottom: 5px dotted yellow;
    }
    

    DEMO

    EDIT:

    If you want a fixed width you can add:

    h1:before, h1:after{
        width: 150px;     /* You can change this value */
        left: 50%;
        transform: translateX(-50%);
    }
    

    DEMO2

提交回复
热议问题