Align H1 Header and Normal Text in Same Line
Solution 1
Original answer (still working just fine)
See the snippet below. The idea is to make the <h1>
inline to allow the second text to be at the same line.
header { border-bottom: 1px solid #000; }
header > h1 { display: inline-block; }
header span { margin-left: 100px; }
<header>
<h1>Text</h1>
<span>text2</span>
</header>
2020 Update
See the snippet the snippet below that makes use of Flexbox. So 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;
}
<header>
<h1>Text</h1>
<span>at the end</span>
</header>
Solution 2
I came up with a simple solution. My requirements are slightly different in that I want my status right aligned.
.my-header h2 {
display: inline;
}
.my-header span {
float: right;
}
<div class="my-header">
<h2>Title</h2>
<span>Status</span>
</div>
<div style="clear:both"></div>
Solution 3
Add this line border-bottom:1px solid #000
<div style="border-bottom:1px solid #000;">
<div align="left"><h1>Header</h1></div>
<div align="right">Regular Text Goes Here</div>
</div>
Use class name instead of inline-style.
Solution 4
Try
<div style="float:left;"><h1>Header</h1></div>
<div style="float:right;">Regular Text Goes Here</div>
instead?
Solution 5
There are two methods to accomplish H1 and TEXT inline. To clarify, TXT is in an element container. You suggest DIV, but any symantic element will do. Below, h1 and p illustrate a common use, while showing that you need not hide from element blocking, using DIV's (though divs are pandemic for many javascript coders).
Method 1
.inline { display: inline; float: left; padding-right: 2rem; }
<h5 class="inline">Element a's link family...</h5>
<p class="inline">
Method 2
h5 { display: inline-block; float: left; font-size: 1rem; line-height: 1rem; margin-right: 2rem; }
h5>p { display: inline-block; float: right; }
<h5>Title</h5>
<p>Paragraph</p>
Mike
Updated on October 18, 2020Comments
-
Mike over 3 years
I'm trying to have a H1 header and regular text on the same line, with a line under it, like so:
I have tried this, but have been unsuccessful
<div style="border-bottom:1px;"> <div align="left"><h1>Header</h1></div> <div align="right">Regular Text Goes Here</div> </div>
What am I doing wrong?
-
Mark about 6 yearslinks are dead now
-
Shuo Feng over 4 yearsIf you just want to modify this specific header, you could just inline the style as codepen.io/sefeng/pen/vYYXROW