How to CSS a two column list of items?

前端 未结 7 781
萌比男神i
萌比男神i 2021-01-04 03:39

I need to display a two column list of items according to the following rules:

  • Container for the columns has fluid width
  • Width of both columns needs t
7条回答
  •  臣服心动
    2021-01-04 04:03

    CSS can't do this. You need to collect the list on the server and distribute the items in two table columns (you can use CSS to make the two columns the same width).

    Note: There are browser extensions for multi column layout but they are not portable.

    [EDIT] I'm aware of the article on alistapart but I can't see a difference to my solution: The proposed multi column layout gives each item a fixed position (by giving each item a unique CSS ID and then positioning it somehow). This means you need to generate the HTML and sort the items on the server and then use lots of tricks to position them.

    It's much more simple to use a table with two columns and drop the items into them during rendering.

提交回复
热议问题