rodneyrehm / viewport-units-buggyfill

Making viewport units (vh|vw|vmin|vmax) work properly in Mobile Safari.
MIT License
1.59k stars 151 forks source link

Adds option to customize stylesheet attachment. #84

Closed gabrielloeb closed 7 years ago

gabrielloeb commented 7 years ago

I don't know if this change might interest you, but it was one that I required for my purposes. Use case: override stylesheets in document body.

rodneyrehm commented 7 years ago

thanks for trying to improve the buggyfill!

in which situation would one add <style> to <body> instead of <head>?

gabrielloeb commented 7 years ago

In my testing, if a <style> tag containing viewport units occurs in the document <body>, it is not overridden if the buggyfill <style id="patched-viewport"> tag is appended to <head>. On the other hand it works as expected if moved to follow them in the document. The change would optionally handle viewport units in stylesheets written in the document <body> where I think the current approach does not.

Admittedly if this case interested you, handling it could be further constrained than a querySelector accepting any string.

rodneyrehm commented 7 years ago

As there's no way (and reason?) to work with scopes, I don't think it makes sense to provide a selector here, as you'd either append to <head> or <body>. So I'd make that option a boolean (defaulting to false) called appendToBody.

rodneyrehm commented 7 years ago

Thank you! I've merged your changes to master 19d6698. I've added a bit of CSS to <body> to properly demo this in index.html