Incomplete borders around div

后端 未结 5 1544
日久生厌
日久生厌 2021-02-12 09:09

I am looking for a way to create an incomplete square with borders with some text and a background with pure css. Here is what I am trying to achieve:

<

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-12 09:33

    Well, go with the above answers, I recommend using pseudo elements to achieve this effect.

    But There is another way to accomplish this without using pseudo-elements.

    Here is how you should do this.

    .row{display:table;table-layout:fixed;}
        .col{display:table-cell;}
        
        .row{width:250px; margin: auto;}
        .mid.row > .col{ height: 100px; }
        
        .col{ text-align: center;}
        .top.col, .bottom.col{
          border-top: 1px solid black;
          border-left: 1px solid black;
          border-right: 1px solid black;
          height: 50px;
        }
       .bottom.col{
         border-top: 0;
         border-bottom: 1px solid black;
       }
        .mid.row > .col{
          border-left: 1px solid black;
          border-right: 0;
          vertical-align: middle;
          text-align: right;
        }
       .mid.row > .col span{
          margin-right: -30px;
         max-width: 300px;
        }
    Hey you can achieve this without using pseudo elements :)

提交回复
热议问题