I am in search of a way to create a separator with text positioned right in the center. When I say center, I mean both horizontally and vertically aligned - there are various methods available such as using pseudo elements or adding an extra span element in the middle.
Below is a snippet of code that I usually use which involves utilizing the span technique:
h2.centre-line
{
width:40%;
text-align:center;
border-bottom:0.1rem solid #ccc;
line-height:0.1em;
margin:2.5rem 30%;
}
h2.centre-line span
{
background-color:#fff;
padding:0 1rem;
}
<h2 class="centre-line"><span>Text</span></h2>
All the examples I have encountered so far have the text placed on a transparent background with margins surrounding it. However, my aim is to position the text within a container of certain height while keeping it centrally aligned.
Thus far, I have struggled to modify my existing code successfully and haven't found any other relevant examples to guide me further.
Any suggestions?