Two distinct elements can break the HTML semantics as it will insert content redundancy into the document. One of the elements <h1>
would be merely aesthetic and adds nothing to the content, so it should not be in the content. To avoid this, one can use the element :after
:
h1 {
position: relative;
}
h1:after {
content: attr(title);
position: absolute;
bottom: 0;
left: 0;
transform: scaleY(-1);
transform-origin: bottom;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.5) 80%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<h1 title="Reflection">Reflection</h1>
So, however, with CSS in the element :after
there is no way to search for the contents of the parent element (not yet, at least), but it is possible to search for an attribute of this element, such as the attribute title
. It is important to note that even being the same content of the element, this will not characterize redundancy, because semantically the text of title
shall be treated differently from the content and there shall be no problem with being equal.
The attribute title
, is a global attribute, which means that all HTML elements support.
A similar effect would be possible using the function element
CSS, but it has almost no support today. With this function, you can set another element of the document as background, so you can generate the shadow including all the color effects in your source:
h1 {
position: relative;
}
h1:after {
content: '';
width: 100%;
height: 100%;
transform: scaleY(-1);
transform-origin: bottom;
background: -moz-element(#foo) ;
position: absolute;
bottom: 0;
left: 0;
}
span {
color: red;
}
.alert {
padding: 20px;
background-color: #f44336; /* Red */
color: white;
margin-bottom: 15px;
}
<div class="alert">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
Este exemplo só funciona no <strong>Firefox</strong>
</div>
<h1 id="foo">Reflec<span>t</span>ion</h1>
The result, for those who don’t have Firefox (or are too lazy to test) is:
Although the two solutions use virtually the same CSS, yours is not working in Firefox. How bizarre. PS: my comment was before EDIT
– fernandosavio
@fernandosavio the first should work, but it must be because I used only the prefix
-webkit
. I’ll see what Firefox didn’t recognize and adjust.– Woss