Horizontal Line in Background using Css3

前端 未结 8 1331
走了就别回头了
走了就别回头了 2021-02-07 08:05

How to implement this type of style to text using only css3, means a horizontal line in the middle of the tag... Can it be possible using pure css...

8条回答
  •  我在风中等你
    2021-02-07 08:39

    You could add a pseudo-element to the paragraph selector like so:

    p {
      ::before {
        border-top: 10px solid #0066a4;
        content:"";
        margin: 0 auto; /* this centers the line to the full width specified */
        position: absolute; /* positioning must be absolute here, and relative positioning must be applied to the parent */
        top: 12px; left: 0; right: 0; bottom: 0;
        z-index: -1;
      }
    }
    

    See this CodePen by Eric Rasch for a working example: https://codepen.io/ericrasch/pen/Irlpm

提交回复
热议问题