2

This question is pretty short on purpose, but I'm very curious if it's possible.

Can you fetch other styles inside a CSS Stylesheet "with" CSS?

A bit like doing this with jQuery:

var header_height = $('#header').css('height');

So I can do calculations like this:

#content {
    height: calc(100% - property('#header', 'height') - property('#footer', 'height'));
}

Where property would then for example represent the fetching of another tag's CSS-style.

No JavaScript allowed for this question ^^

1
  • 2
    Nope. This can't be done. Commented Mar 7, 2013 at 8:13

1 Answer 1

4

A short answer: no it's not possible with pure CSS. You can only do that with JavaScript or with restrictions in languages like SASS or LESS that generate pure css. But if the dimensions change dynamically, both won't help either.

Your only chance in CSS is with percentages like

#content {
    height: 80%;
}

where the height changes accordingly to the parents height. But this only works with parent elements of course.

Sign up to request clarification or add additional context in comments.

3 Comments

Sad, but logical I guess :)
This came up to me when I answered this question (stackoverflow.com/questions/15264255/…) and was wondering if you could dynamically fetch the #header and #footer height for the #content. I guess it's not very hard to do it manually. But who doesn't love dynamics? :)
Yeah, it would be cool if CSS had some simple calculation possibilites.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.