drewwyatt
drewwyatt

Reputation: 6027

Can I grab the height of an unrelated element that has a dynamic height with Sass?

I have 2 unrelated elements: #A and #B (in terms of hierarchy). #A does not have a predefined height. I would like #B to end up being the height of #A minus 325px.

I know Sass can handle operations, but I am unsure of how to query the height of #A - is that even possible?

Upvotes: 2

Views: 292

Answers (2)

Not possible with CSS or SASS, plain easy with jQuery:

$('#b').outerHeight( $('#a').outerHeight() - 325 );

Demo: http://jsbin.com/ulimon/2/edit

Upvotes: 1

ITChristian
ITChristian

Reputation: 11271

Sorry, but I think is not possible to get a element height with SASS (i'm not an expert in sass, but I couldn't find any option).

I recommend you to do this with JavaScript:

http://jsfiddle.net/9DcYn/2/

window.onload = fixHeight();
function fixHeight() {
    var divh = document.getElementById('leftdiv').offsetHeight;
    var divhnum = new Number(divh);
    var setheight = (divhnum - 325);
    document.getElementById('rightdiv').style.height = setheight + 'px';
}

Hope this will help you!

Upvotes: 1

Related Questions