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

  • Home
  • SEARCH
  • 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 6470163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:04:39+00:00 2026-05-25T06:04:39+00:00

I am trying to get the width of an element according to it’s CSS

  • 0

I am trying to get the width of an element according to it’s CSS rules The problem is that “getComputedStyle” returns a pixel value instead of “auto” for an element with no CSS width value set. In Opera, “elem.currentStyle[‘width’]” returns “auto”, but in firefox, it must use “getComputedStyle” which returns something like “1149px”.

It is vital for me to know what the actual CSS rule is. Is there some way of doing this besides besides getComputedStyle? The Firefox MDN makes it clear “getComputedStyle” is not the way to go, but I cannot find any documentation for a Firefox equivalent to “currentStyle”.

If you want to know, my end goal is to find the largest static-width element on the page.
If I cannot read stylesheet values – only rendered/computed values –
then how can I achieve this?

  • 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-25T06:04:40+00:00Added an answer on May 25, 2026 at 6:04 am

    If you start with an element, there is no way to know which stylesheet rules applied to it. getComputedStyle() merely gives you the effective style value and currentStyle isn’t much different even though it happens to give you the result you expect in this particular scenario and this particular browser.

    What you probably need to do is to go through the stylesheets instead. Along the lines of:

    for (var i = 0; i < document.styleSheets.length; i++)
    {
      var styleSheet = document.styleSheets[i];
      for (var j = 0; j < styleSheet.cssRules.length; j++)
      {
        var rule = styleSheet.cssRules[j];
        if (rule.type == 1)  // STYLE_RULE
        {
          // Do something with rule.style.width
        }
      }
    }
    

    If you then need to locate elements matching that rule you can use document.querySelectorAll() with rule.selectorText. The remaining problem is that multiple style rules might apply to the same element and the specificity of the rule needs to be calculated. Not sure how much this is a problem for you however.

    Additional documentation:

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

Sidebar

Related Questions

I'm trying to get the width of a div container to set another css
I'm trying to get the width of an element with jQuery and then paste
I'm trying to get the value of an inherited CSS property using Javascript. I
I'm trying to get element by name, and I have a problem This is
Im trying to get a Gutter Width of 10px between my Div's, but it
I'm trying to get a JEditorPane to highlight the full width of a displayed
Trying to get comfortable with jQuery and I have encountered some sample code that
I am trying to change the background property in DataTemplate according to AttachedProperty value
I am trying to scale images to fit within their parent element width, and
I'm trying to get a navigation bar that consists of a nav with an

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.