Reputation: 4666
I want to make the width of the footer browser-independent.
For Firefox, I want to use the value of -moz-available
, and when a user uses Opera, then CSS should get the values from -webkit-fill-available
.
How can I do this in CSS?
I tried to do something like this:
width: -moz-available, -webkit-fill-available;
but this won't give the desired results.
Upvotes: 125
Views: 266954
Reputation: 128791
CSS will skip over style declarations it doesn't understand. Mozilla-based browsers will not understand -webkit
-prefixed declarations, and WebKit-based browsers will not understand -moz
-prefixed declarations.
Because of this, we can simply declare width
twice:
elem {
width: 100%;
width: -moz-available; /* WebKit-based browsers will ignore this. */
width: -webkit-fill-available; /* Mozilla-based browsers will ignore this. */
width: fill-available;
}
The width: 100%
declared at the start will be used by browsers which ignore both the -moz
and -webkit
-prefixed declarations or do not support -moz-available
or -webkit-fill-available
.
NB: fill-available
(which is in the spec as stretch
) is still experimental, and should not be used in production.
Upvotes: 282