Boris Kozarac Boris Kozarac - 6 months ago 13
CSS Question

Align span inside title to the right

How can I align subtitle to the right without using float? I need it to be on the same level as title.

<h2>Title <span>Subtitle</span> </h2>

h2 {
border: 1px solid #333;
font-size: 50px;
}

span {
font-size: 20px;
}

Answer

Flexbox can do that.

h2 {
  border: 1px solid #333;
  font-size: 50px;
  display:flex;
  align-items:baseline;
}

span {
  font-size: 20px;
  margin-left:auto;
}
<h2>Title <span>Subtitle</span> </h2>