Currently, I am working on a CSS project that requires page titles (headings) to be centered with horizontal lines positioned vertically on both sides. Additionally, there is a background image on the page which means the title's background must be transparent.
I have successfully centered the title and used pseudo-class to create the line. However, my challenge lies in making the line disappear when it crosses the text of the title.
One solution I considered was using a background gradient that turns transparent where the words are located. But due to varying title lengths, determining where to place the stops would be problematic.
Below is the current CSS code snippet:
h1 {
text-align: center;
position: relative;
font-size: 30px;
z-index: 1;
}
h1:after {
content: '';
background-color: red;
height: 1px;
display: block;
position: absolute;
top: 18px;
left: 0;
width: 100%;
}
This is my progress so far: http://jsfiddle.net/XWVxk/1/
Is it possible to achieve this effect using pure CSS without any additional HTML elements?