I've got some elements on the page that have a before pseudo element whose height is styled with the CSS calc() function; something like this:
.el:before: {
content: "";
height: calc(50% + 10px);
}
I want to use this method to get the height of the :before element - and in Webkit-based browsers it works and returns a pixel value.
var height = window.getComputedStyle(
document.querySelector('.el'), ':before'
).getPropertyValue('height');
In Firefox, however, it returns the actual string of the CSS rule (exactly 'calc(50% + 10px)').
(function() {
var height = window.getComputedStyle(
document.querySelector('.myelem'), ':before'
).getPropertyValue('height');
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>
Is there any work-around for this?