Deconstructing Your Code (and its pitfalls)
Upon reviewing your initial code snippet, there are a couple of observations to be made:
-webkit-height: 5.2vh;
-moz-height: 5.2vh;
-ms-height: 5.2vh;
-o-height: 5.2vh;
height: 41px; /* Used as a fallback */
The prefixes, such as -webkit-
, are only valid if they correspond to a specific property. In the case of height, these prefixed properties are unnecessary and will be disregarded by browsers.
(Pro Tip: For a comprehensive list of CSS properties, you can refer to resources like MDN)
Resolution Strategy:
To address this issue effectively, we can leverage the behavior where browsers skip over unrecognized properties or values. Therefore, consider implementing the following adjustment:
height: 41px;
height: 5.2vh;
When encountering height: 41px
, the browser interprets it as intended. Subsequently, when presented with height: 5.2vh
, the browser either utilizes the vh
unit if supported, similar to how it would process color: blue; color: red;
. Conversely, if the vh
unit is not recognized, it is simply ignored. By establishing the fallback initially, any disregard for the vh
unit does not impact functionality.
Clearer now?