Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6731613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:33:00+00:00 2026-05-26T10:33:00+00:00

I want to set the height of a div based on CSS expression. Basically

  • 0

I want to set the height of a div based on CSS expression.

Basically it should be set as some % (say 90%) of the viewport width
I tried the following, but is not working;

height:expression(document.documentElement.clientWidth ? document.documentElement.clientWidth : window.innerWidth );

I am looking at a cross-browser way of doing this (IE7+, FF4+, Safari)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:33:00+00:00Added an answer on May 26, 2026 at 10:33 am

    CSS expressions are not supported anywhere except IE (and are considered a bad idea even there).

    However, there isn’t really another way of doing what you’re asking, at least not using just CSS.

    The only alternative is to use Javascript, and this is what I think you’re going to have to do.

    In fact, IE’s CSS expressions are themselves Javascript, which allows quite powerful expressions, but also has the negative effect of removing the abstraction of layout and script. This is why they’re frowned on, but there are use cases such as yours where pure layout requires some form of expression.

    As I say, there really isn’t any answer for you right now in CSS.

    There might be some hope for the future, as Google are currently experimenting with some enhancements to CSS which include variables. Article about it here: http://johanbrook.com/design/css/webkit-css-variables-mixins-nesting/. However, I’m not sure whether even this would allow the kind of expressions you’re needing.

    So possibly this is something that might continue needing needing Javascript into the future. It certainly does for now, either way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div with an id main, I want to set its height
I have a div that I want to set the height of to 1/2
I want to set height of a div as height of window when page
I want to set the height of asp:panel to auto and I also want
I want to set a background image for a div, in a way that
I want to set some attributes just before the object is serialized, but as
Im trying to set an automatic height a div that contains 2 child elements,
I have a div with a set height of 200, and sometimes there's enough
This should be simple but nothing's working: Question How do you set the height
I was wondering if there is a way with CSS to set the height

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.