I believe I was able to accomplish what you want with the use of flexbox. TL;DR: see snippet below.
First, I nested div.sub-title
within div.title
in the HTML.
Then, I turned the div.title
into a flex container with display: flex
, and set the flow direction to column
. Adding align-items: center
centers the elements within the container.
Next, I targeted the first h1
element, adding a border-top
and border-bottom
. You can make it however thick you like—I put 4px
. If you want to add or reduce the spacing between the borders and the title, adjust the padding
.
I then targeted the div.sub-title
container. I gave it a position
of relative
and then offset its position vertically with top: -45px
. You may want to adjust this value to get it centered the way you want it. I applied a zero line-height
to remove the default value which is pretty tall on a heading. To adjust the spacing between the sub-title and the line on either side, add padding
to div.sub-title
—I used 20px
. Lastly, add a background color that matches your page's background.
While this works, it'll largely depend on how much pre-defined values you're able to use (like padding
and background-color
).
Another thing to note is when the screen width gets too small, and the subtitle wraps, it'll look really ugly. This is due to the line-height
being set to zero. To fix, you can set a min-width
on div.title
to prevent the entire container from going below a certain width or reset the line-height
in div.sub-title
at a certain breakpoint with a media query.
.title {
display: flex;
flex-flow: column nowrap;
align-items: center;
min-width: 350px;
}
.title > h1 {
display: inline;
padding: 30px 0;
border-top: 4px solid black;
border-bottom: 4px solid black;
text-align: center;
}
.sub-title {
position: relative;
top: -45px;
/* reset this w/ a media query when screen size gets too small */
line-height: 0px;
padding: 0 20px;
background-color: #fff;
}
<body>
<div class="title">
<h1>Tomorrow Or Something Longer</h1>
<div class="sub-title">
<h1>Today or something</h1>
</div>
</div>
</body>