Skip to content Skip to sidebar Skip to footer

Border Line Next To Text

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

Categories

I want

Solution 1:

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>

Solution 2:

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;
}

Solution 3:

p{

}

P:after{
    content:'________';
}

DEMO


Solution 4:

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;
}

Solution 5:

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

Post a Comment for "Border Line Next To Text"