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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:36:10+00:00 2026-05-31T23:36:10+00:00

I have written some JS and CSS that allows certain columns to be flexible

  • 0

I have written some JS and CSS that allows certain columns to be flexible and when the browser is resized (or by default) making a column thinner than it’s original width then I remove the flexible ability. This works fine in this example: http://dev.driz.co.uk/FlexGrid.html as you will see as you resize the browser the window the red cell either fills the screen or becomes a fixed width. This is because you need at least one 100% cell for proper table-layout fixed to work as intended with cols.

The problem I am having though is that when I have TWO flexible columns the function runs on one of them BEFORE the other (at least I think as much) and means that only ONE column will have its flex class re-added. It’s fine removing it but can’t reapply the flexible state if the cell gets larger than its original. See the example here: http://dev.driz.co.uk/FlexGrid2.html

Can anyone help? Offer suggestions to improve the code to get the function to work on BOTH flexible columns.

  • 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-31T23:36:11+00:00Added an answer on May 31, 2026 at 11:36 pm

    The code was almost spot on, you only had it in the wrong order.

    Before you had it declaring multiple updateWidth() function declarations and binding the window resize event for as many columns that have the class flex, in this case being twice. This resulted in the events being fired separately one after another. So I moved that out of the .each() call, and put that .each() inside the function instead and it seems to work now.

    $(document).ready(function() {
    
        // function declaration
        function updateWidth() {
    
            $('col.flex').each(function() {
    
                var flex = $(this);
    
                var original = flex.data('original');
    
                var flexIndex = flex.index() + 1; /* Add 1 because JS and CSS differ with indexes */
    
                var flexCell =  $('.uiGrid table tbody td:nth-child(' + flexIndex + ')');
    
                flexCell.css({'background':'#ff0000'});
    
                //////////////////////////////////////////////////////////////
                if(flexCell.width() < original) {
                    $('col.flex').removeClass('flex-width');
                }
                else if(flexCell.width() >= original) {
                    $('col.flex').addClass('flex-width');
                }
            });
    
        }
    
        // initial call
        updateWidth();
    
        // subsequent call upon window resize
        $(window).bind('resize', function() {
            updateWidth();
        });
    
    });
    

    I had to add another class for the flex function to work. One class to denote that the column is always flexible (flex) and another class to control the width of the column (flex-width). This means we can add/remove the flexible width without losing the fact that the column is flagged as flexible.

    Another minor code tweak I made, which didn’t stop it initially working but was redundant, was to remove any double-jquery’ed objects. One example was :

    var flex = $(this); // flex is now a jquery object
    var original = $(flex).data('original'); // flex is turned into a jquery object again
    

    to

    var flex = $(this); // flex is now a jquery object
    var original = flex.data('original'); // flex is already a jquery object, so can reference it as a var
    

    See code at : http://jsfiddle.net/GoranMottram/TysFf/1/
    See demo at : http://jsfiddle.net/GoranMottram/TysFf/1/embedded/result/

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

Sidebar

Related Questions

I have written some CSS which targets elements using the parent > child selector.
I have written some code to ensure that items on an order are all
I have written some WebGL code, actually I am playing with the examples that
We have a CMS that likes to insert inline styles, I have written some
I am working with some CSS that is poorly written to say the least.
I have written code that automatically creates CSS sprites based on the IMG tags
I have a gridview that has some 20 columns and 1000 rows. The grid
I have written some code in my VB.NET application to send an HTML e-mail
I have written some code for playing a .wav through my application. Now I
I have written some jQuery ajax code where I am sending a request to

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.