Not sure about "industry standard", but it's a very handy technique and not too difficult. The content of pseudo elements is not available via text()
though, you have to use getComputedStyle
.
Example using body:after
:
Sass (using the compass breakpoint extension):
body:after {
display: none;
@include breakpoint($bp-wide) {
content: "wide";
}
@include breakpoint($bp-medium) {
content: "medium";
}
@include breakpoint($bp-small) {
content: "small";
}
}
JavaScript:
if (window.getComputedStyle) {
var mq = window.getComputedStyle(document.body,':after').getPropertyValue('content');
}
if (mq.indexOf('small') !== -1) {
// do something
}
Credit: I first saw this technique here: https://coderwall.com/p/_ldtkg
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…