I am seeking to implement a unique design for a piece of text that will not show a particular character visually, but includes the character for other functional purposes. For instance, the interface might display something like
<sup><sub>$</sub></sup>123<sup><sub>45</sub></sup>
, while the actual text content is $123.45
.
- If you highlight and copy the displayed text using Ctrl+C, the clipboard should store the underlying text.
- If you right-click on the displayed text, the context menu should offer an option such as
Search Google for "<em>X</em>"
where X represents the hidden text (if supported by the browser). - Both screen readers and search engine crawlers should be able to access the concealed text.
This is the approach I'm currently using:
body {
font-family: sans-serif;
}
.price {
line-height: 4.4rem;
font-size: 4rem;
}
.cc, .cf {
font-size: 0.6em;
vertical-align: super;
margin: 0 2px;
}
.cs {
opacity: 0;
margin: 0 0 0 -.28em;
}
.ci {
font-size: 4.4rem;
}
<span class="price" aria-label="$123.45">
<span class="cc">$</span><span class="ci">123</span><span class="cs">.</span><span class="cf">45</span>
</span>
However, I have concerns about using an invisible element with opacity: 0
—it feels somewhat deceptive and could possibly be flagged by certain advanced crawlers. Additionally, the -.28em
adjustment may not be universally effective across different fonts or font sizes.
I am considering changing the style of .cs
to display: inline-block; width: 0
to address the margin issue, but this could lead to challenges when selecting parts of the text. Keeping .cs
inline appears crucial in ensuring seamless selection of the entire text block.
Thus, my question revolves around determining the most semantically appropriate method, utilizing HTML5 and CSS, to manage distinct content for visual and interactive purposes.