Text in Border CSS HTML

后端 未结 8 2121
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 05:56

I\'d like to have a div that looks like this:

\"border

Is this possible to do with HTML + CSS

8条回答
  •  忘了有多久
    2020-11-22 06:32

    Text in Border with transparent text background

    .box{
        background-image: url("https://i.stack.imgur.com/N39wV.jpg");
        width: 350px;
        padding: 10px;
    }
    
    /*begin first box*/
    .first{
        width: 300px;
        height: 100px;
        margin: 10px;
        border-width: 0 2px 0 2px;
        border-color: #333;
        border-style: solid;
        position: relative;
    }
    
    .first span {
        position: absolute;
        display: flex;
        right: 0;
        left: 0;
        align-items: center;
    }
    .first .foo{
        top: -8px;
    }
    .first .bar{
        bottom: -8.5px;
    }
    .first span:before{
        margin-right: 15px;
    }
    .first span:after {
        margin-left: 15px;
    }
    .first span:before , .first span:after {
        content: ' ';
        height: 2px;
        background: #333;
        display: block;
        width: 50%;
    }
    
    
    /*begin second box*/
    .second{
        width: 300px;
        height: 100px;
        margin: 10px;
        border-width: 2px 0 2px 0;
        border-color: #333;
        border-style: solid;
        position: relative;
    }
    
    .second span {
        position: absolute;
        top: 0;
        bottom: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    .second .foo{
        left: -15px;
    }
    .second .bar{
        right: -15.5px;
    }
    .second span:before{
        margin-bottom: 15px;
    }
    .second span:after {
        margin-top: 15px;
    }
    .second span:before , .second span:after {
        content: ' ';
        width: 2px;
        background: #333;
        display: block;
        height: 50%;
    }
    FOO BAR

    FOO BAR

提交回复
热议问题