Border line next to text

后端 未结 5 648
予麋鹿
予麋鹿 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 <strong> 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 */
    }
    <p class="hasBorder">
      <strong>Categories</strong>
    </p>

    0 讨论(0)
  • 2021-01-22 12:45
    p{
    
    }
    
    P:after{
        content:'________';
    }
    

    DEMO

    0 讨论(0)
  • 2021-01-22 12:52

    JS Fiddle

    p {
        font-size: 12px;
        margin-bottom: 2px;
        position:relative
    }
    p::after {
        content:"";
        border-bottom:1px solid grey;
        width:100px;
        position:absolute;
        bottom:2px;
    }
    
    0 讨论(0)
  • 2021-01-22 12:54

    p {
      margin-left: 0px;
      font-size: 12px;
      margin-bottom: 2px;
      position: absolute;
      margin-top: -7px;
      background-color: #fff;
      color: #333;
      padding-right: 5px;
    }
    .line-back {
      border-bottom: 1px solid #ccc;
      margin: 25px;
    }
    <div class="line-back">
      <p>
        <strong> Categories</strong>
      </p>
      </div

    0 讨论(0)
  • 2021-01-22 13:01

    Use a pseudo element

    Jsfiddle Demo

    CSS

    p {
        font-size: 12px;
        margin-bottom: 2px;
        overflow: hidden;
        position: relative;
    
       }
    
    p:after {
        content:"";
        position: absolute;
        border-bottom:1px solid grey; /* border-size & color are now controllable */
        width:100%;   
        height:1em;
        display: inline;
        margin-left: 1em;
    }
    
    0 讨论(0)
提交回复
热议问题