3

How to make hr element be inline like I do it in snippet, but without absolute positioning and without hr crossing text?

div {
    position: relative;
}

hr {
  position: absolute;
  top: 0.125rem;
  left: 0;
  right: 0;
}
<div>
  Hello, World? <hr>
</div>

1 Answers1

4

You could use display flex on the parent and then give the hr flex grow so it fills the rest of the line:

div { display:flex; }

hr {
  flex-grow:1;
  margin-left:10px; /* gap on left */
}
<div>
  <span>Hello, World?</span> <hr>
</div>
Pete
  • 57,112
  • 28
  • 117
  • 166