css divide width 100% to 3 column

前端 未结 11 617
余生分开走
余生分开走 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条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 22:37

    Just in case someone is still looking for the answer,

    let the browser take care of that. Try this:

    • display: table on the container element.
    • display: table-cell on the child elements.

    The browser will evenly divide it whether you have 3 or 10 columns.

    EDIT

    the container element should also have: table-layout: fixed otherwise the browser will determine the width of each element (most of the time not that bad).

提交回复
热议问题