Reactive Columns with Maximum Maximum Width

I need it very simply, or at least it should be, but after several days of research, I came to go to stackoverflow if anyone really knows how to do this ...

I have 3 columns of content, all of which have extensible content inside. Not a single content is very wide, but it is a lot (once expanded). I need to do this so that when expanding the content in one column, it reduces the other two columns to a certain amount, and when you expand the content of two columns, it is aligned, etc. Then the columns must have a percentage of maximum size and minimum size (in percent or static), so when the columns expand, they do not completely hide the rest, and therefore I can set the maximum “extensibility” for each column. For simplicity, here is an example that would do the trick if it only worked:

<table width="100%"><tr>
<td style="min-width:200px; max-width:60%;">Col1ExpandableContent</td>
<td style="min-width:200px; max-width:50%;">Col2ExpandableContent</td>
<td style="min-width:200px; max-width:40%;">Col3ExpandableContent</td>
</tr></table>

The above code does not work, but I'm sure you can imagine how it will work if it does. This is exactly what I need, only that max-width for some reason does not work with percentages on TD. If you need better visualization, I made a fiddle to help illustrate the problem here: http://jsfiddle.net/m5xgcf3s/

cols - , , . , ( , TD , ) , (, , ). , javascript, , , , . , , heck max-width ...

:



, , script, ... NO frameworks, NO jQuery, NO hacks, TDs id ;

<script type="text/javascript">
      window.onresize=function setTDmaxwidth() {
      var containerwidth = window.innerWidth;
        if (containerwidth >= 400 ) {                                                                                                   
            document.getElementById("col1").style.maxWidth=( ( containerwidth * 0.6 )+'px');
            document.getElementById("col2").style.maxWidth=( ( containerwidth * 0.5 )+'px');
            document.getElementById("col3").style.maxWidth=( ( containerwidth * 0.4 )+'px');
        } else {  }
    }
</script>

, , ( 100% iframe). , ( ), , , , TDs

+4
2

?

tr td.

.

, - ..

Css

    <style type="text/css">
        td { border: 1px solid black; }

    </style>    

Script

    <script>
    function onLoadFunction(){
        if(($(".tdFirst div").text().length)<100){
            $(".tdFirst div").css('width','200px'); // min width
        } else if(($(".tdFirst div").text().length)>=400) {
            $(".tdFirst div").css('width','400px'); //max width
        } else {
            $(".tdFirst div").css('width',$(".tdFirst div").text().length+'px'); //width auto adjust 
        }
    }
    </script>

HTML

    <body onLoad="onLoadFunction()">
        <table>
            <tr>
                <td align="center"class="tdFirst">
                    <div>
                        Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test 
                    </div>
                </td>
                <td><p>testing...</p></td>
            </tr>
        </table>
    </body>

# 2

script jQuery

    $('document').ready(function(){
        $(".tdFirst div").each(function(){
            if(($.trim($(this).text()).length)<50){
                $(this).css('width','20px'); // min width
            } else if(($.trim($(this).text()).length)>=60) {
                $(this).css('width','60px'); //max width
            } else {
                $(this).css('width',$.trim($(this).text()).length+'px'); //width auto adjust 
            }
        });
    });
0

, px, , .

: http://jsfiddle.net/qoaxxbqp/

, div, , :

<div  style="width:600px;border:2px blue solid;" >
   <table width="500px"><tr>
    <td style="min-width:100px; max-width:60%;">Col1ExpandableContent</td>
    <td style="min-width:100px;max-width:50%;">Col2ExpandableContent</td>
    <td style="min-width:100px; max-width:40%;">Col3ExpandableContent</td>
   </table>
</div>

, div : 100% . , / ( % ).

jquery hover in/out .

0

All Articles