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 6915195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:26:41+00:00 2026-05-27T09:26:41+00:00

We have a situation in our project when resizing a container. It seems to

  • 0

We have a situation in our project when resizing a container.
It seems to be impossible to keep the “auto” value for our elements margin.

For example when trying to get the margin value with javascript or jquery, the value always returns 0. We really need to keep “auto” when resizing, so is there a way to determine which elements have margin: auto;

Even if it’s possible using raw javascript?

—————– Possible solution but needs Extending —————–

I have found this useful. Which in fact solves part of the problem!

Retrieve element margin if it's 'auto' (Answer 3)

if($(this).position().left*2 == ($(this).parent().innerWidth() - $(this).outerWidth())) {
  console.info($(this).attr('id'));
}

However this matches far to many elements, so need to somehow be more specific.
hopefully someone knows how to improve this code?

  • 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-27T09:26:42+00:00Added an answer on May 27, 2026 at 9:26 am

    Thanks to Vigrond previous answer above.
    I was able to research further into the CSS Rule Object.

    Finally I have come up with my own solution to return the actual CSS rules direct from the style-sheet! This not only solves my problem with margin auto, it also allows me to return all other css values which are not returned by the jquery CSS object.

    Although the code could be optimized further.
    I am very happy with the result, also I added a white list as in my case it is not necessary to loop through all style-sheets.

    Here is the code I ended up with!

    var cssObj  = {};
    function getStyle(element) {    
      var extractStyles = function(cssText) {
        var css = {};
        regEx   = /\.*\{[^\}](.*)}/im;
        styles  = cssText.match(regEx)[1].split(';');
        $.each(styles, function(k, style) {
          $key = style.split(':')[0].trim();
          $val = style.split(':')[1];
          if($key != '')
            css[$key] = $val.trim();
        });
        return css;
      };
      var sheets    = document.styleSheets;
      var whiteList = [
        cssPath+'product.css',
        cssPath+'style.css'
      ];
      $.each(sheets, function(key, sheet) {
        if($.inArray(sheet.href, whiteList) >=0) {
          $rules = sheet.rules || sheet.cssRules;
          $.each($rules, function(key, rule) {
            if(element.is(rule.selectorText)) {
              if(typeof(rule.cssText) != 'undefined' && rule.cssText) {
                cssObj[rule.selectorText] = extractStyles(rule.cssText);
              } else {
                cssObj[rule.selectorText] = (typeof(rule.cssText) != 'undefined' ? extractStyles(rule.style.cssText) : '');
              }
            }
         });
        }
     });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use scalaz validation in our project and have ran into a
The situation: We have a library project that houses much of our code for
We have a situation where we need to take a tag of our project
We have a situation in our product where for a long time some data
We have a situation where our application calls some stored procedures on a sql
I have a situation where our developers extended a Third party database (MS SQL)
Currently in our enterprise we have a situation that i think it's not very
We've encountered the following situation in our database. We have table 'A' and table
We have a bit of a messy database situation. Our main back-office system is
We have a large project with several sub-projects. We're approaching a release of our

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.