I\'m trying to have a H1 header and regular text on the same line, with a line under it, like so:
See this CodePen.
The idea is to make the inline to allow the second text to be at the same line.
HTML:
Text
text2
CSS:
header { border-bottom: 1px solid #000; }
header > h1 { display: inline-block; }
header span { margin-left: 100px; }
See this alternative CodePen that makes use of flexbox.
Instead of setting the h1 to an inline-block
, you can make the header a flex
container. A flex container will (by default) layout its children on a horizontal axis. Note that you also need align-items: center
to keep the h1 and span on the same vertical axis.
Also, note that you might want align-items: baseline
if you want the texts to appear on the same baseline (like my original answer).
header {
display: flex;
align-items: center;
/* Remove the next line if you want the span to appear next to the h1 */
justify-content: space-between;
border-bottom: 1px solid #000;
padding: 10px 30px;
}