Hello. I have a question regarding the CSS code for Step 31 of “Learn More About CSS Pseudo Selectors By Building A Balance Sheet.”
We are trying to access elements of the sr-only class to make them invisible to sighted users, while allowing the screen reader to access it for those hard of seeing or blind.
Below is the HTML code for sr-only class span elements:
<thead>
<tr>
<td></td>
<th><span class="sr-only year">2019</span></th>
<th><span class="sr-only year">2020</span></th>
<th class="current"><span class="sr-only year">2021</span></th>
</tr>
</thead>
There are other parts of the code that contain sr-only class elements, but since they all work the same way, I just brought one part of the code.
Below is the CSS code that targets the sr-only class:
span[class~="sr-only"] {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
-webkit-clip-path: inset(50%);
}
Q1. Why is clip: rect(1px, 1px, 1px, 1px); included?
According to clip - CSS: Cascading Style Sheets | MDN, the clip property only applies to absolutely positioned elements (position:fixed or position:absolute). However, by default, the position property for all HTML elements in CSS is static. Thus, the clip: rect(1px, 1px, 1px, 1px); doesn’t have any effect on the elements.
I’d assume that if we wanted to use the clip property, we would do this:
span[class~="sr-only"] {
border: 0;
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
}
Q2. What is -webkit-clip-path and how is it different from clip-path?
I have tried searching Google, but I keep getting the message that it doesn’t match any documents.
Q3. Why not only use clip-path: inset(50%)?
I don’t see any difference in results from only using clip-path: inset(50%). Is there anything going on behind the scenes by using clip and -webkit-clip-path?
Q4. Why do we set border: 0? What effect does it have?