css divide width 100% to 3 column

前端 未结 11 633
余生分开走
余生分开走 2020-12-12 21:38

I have a layout where I have 3 columns.

Therefore, I divide 100% by 3.

The result is obviously 33.333....

My goal is perfect

11条回答
  •  猫巷女王i
    2020-12-12 22:20

    I do not think you can do it in CSS, but you can calculate a pixel perfect width with javascript. Let's say you use jQuery:

    HTML code:

    JS Code:

    $(function(){
       var total = $("#container").width();
       $("#col1").css({width: Math.round(total/3)+"px"});
       $("#col2").css({width: Math.round(total/3)+"px"});
       $("#col3").css({width: Math.round(total/3)+"px"});
    });
    

提交回复
热议问题