The image inside the container element having a specific display type behaves differently when using the img { width: 0; } or img { width: 0%; } style rules.
Increasing the value of width using any unit other than % gave the same expected result (img occupies only the shown part of it).
I've tried changing the display type of the container the img is in. The result is shown below.
Container display types in which the img is shown not as expected:
- -webkit-inline-box
- inline-block
- inline-flex
- inline-grid
- inline-table
- table
- table-cell
- table-row
- table-row-group
- table-header-group
- table-footer-group
Not sure how they're related to each other, probably I'm missing something.
button:first-of-type img {
width: 0;
}
button:last-of-type img {
width: 0%;
}
<h3>The image width: 0 (hides it)</h3>
<button>
<img src="https://picsum.photos/id/1012/200/100">
<p>Add playlist</p>
</button>
<h3>The image width: 0% (occupies the space (natural img width) and hides it)</h3>
<button>
<img src="https://picsum.photos/id/1012/200/100">
<p>Add playlist</p>
</button>
The img { width: 0%; } should work as it was img { width: 0; } without occupying any space, which isn't the case here.