4
CSSのcalc()関数で高さを指定したbefore擬似要素を持つ要素がページにあります。このような何か:pseuso要素にwindow.getComputedStyleを使用するCSSの計算で
.el:before: {
content: "";
height: calc(50% + 10px);
}
私は:before
要素の高さを取得するためにthis methodを使用したい - とのWebkitベースのブラウザでは、それが動作し、ピクセル値を返します。
var height = window.getComputedStyle(
document.querySelector('.el'), ':before'
).getPropertyValue('height');
は、Firefoxでは、しかし、それはCSSルール(正確に'calc(50% + 10px)'
)の実際の文字列を返します。
(function() {
var height = window.getComputedStyle(
document.querySelector('.myelem'), ':before'
).getPropertyValue('height');
\t document.getElementById('result').innerHTML = 'Calculated height is: ' + height;
})();
.myelem {
position: relative;
padding-left: 20px;
}
.myelem:before {
content: "";
position: absolute;
top: 0px;
left: 0px;
width: 1px;
height: calc(50% + 2px);
background-color: red;
}
<div>
<div class="myelem">
<span>Some stuff here</span>
</div>
</div>
<div id="result">
</div>
このため任意の回避策はありますか?
PS://:この問題を回避するために、e.generalovは[バグ報告のコメント](HTTPSで何かを提供していbugzilla.mozilla.org/show_bug.cgi?id=925694#c7)これはうまくいくようです:http://jsfiddle.net/3FecG/3/ – Kaiido