How to style my unordered list like a table?

后端 未结 3 471
余生分开走
余生分开走 2021-01-05 04:19

I have ONLY one

    and under that we have group of
  •  
    • 1
    • 2
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-05 04:32

    It's a really late answer, but I think this is a common topic. Here's a codepen I made.

    Obviously it's just a starting point. It also has some example of how to add styles like bg or borders. If the 'cells' contain some arbitrary content, you'll have to adjust dimensions, for example. I use this kind of code for thumbnails galleries, for example, where you don't have to worry about borders or bgs and it's quite elementary code (the example is for a 2x3 table, see codepen):

    ul{
      list-style:none;
    }
    
    ul li{
      float:left;
      padding:10px;
      border-bottom:1px solid #000;
      border-right:1px solid #000;
    }
    
    ul li:nth-child(3n){
      background-color:#888;
    }
    
    ul li:nth-child(3n+1){
      clear:both;
      border-left:1px solid #000;
      background-color:#ccc;
    }
    
    ul li:nth-child(-n+3){
      border-top:1px solid #000;
    }
    

    Hope it helps.

提交回复
热议问题