DEV Community

Passionate Coder
Passionate Coder

Posted on

::before / ::after in css

Insert some text/image etc before of after and after an element without adding html elments

Use case

image

Sometimes we need to style element like above in such case we can use before and after like below

html

<p>This is paragraph</p> 
Enter fullscreen mode Exit fullscreen mode

css

p {
    display: flex;
    align-items: center;
  }

  p::before {
    content: "";
    margin-right: 10px;
    flex: 1;
    border-bottom: 1px solid #ccc;
  }

  p::after {
    margin-left: 10px;
    content: "";
    flex: 1;
    border-bottom: 1px solid #ccc;
  }
Enter fullscreen mode Exit fullscreen mode

Thanks for reading this if you have any other suggestions to do this better please comment below

For react beginner you can follow me on youtube ( If you want )

React/Javascript Videos (IN Hindi) :

Top comments (0)