Border line next to text

后端 未结 5 649
予麋鹿
予麋鹿 2021-01-22 12:00

I have a p tag. I want a border line next to it.

Categories

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 12:45

    There are many other ways to achieve this, one of them would be applying a border-bottom to a pseudo-element (which establishes a new block formatting context in order to prevent overlapping) and floating the element to the left:

    p.hasBorder {
      overflow: hidden; /* Establish a new block formatting context */
    }
    
    p.hasBorder > strong {
      float: left;
    }
    
    p.hasBorder:after {
      content: "";
      display: block;
      border-bottom: 3px solid silver;
      overflow: hidden;  /* Establish a new block formatting context */
      height: 1em;       /* Up to you */
    }

    Categories

提交回复
热议问题