Understanding CSS table-cell and percentage width

后端 未结 2 1037
渐次进展
渐次进展 2020-12-31 17:10

I was checking how Github display the below menu:

\"enter

If you notice, each

2条回答
  •  春和景丽
    2020-12-31 17:35

    This is something called the 1% width table hack.

    This is because the table-cell inherits it's width from the parent div, allowing you to specify a related percentage of the cell width.

    Here is a working demo on CodePen that you can play with and examine further.

    http://codepen.io/ld0rman/pen/FCiLh

          
    

    CSS:

      ul {
     list-style-type: none; 
     margin: 100px auto;
      width: 80%;
     }
    
     li {
       display: table-cell; 
       width: 1%;
        text-align: center;
        }
    
          a {
         display: block;
            border: 1px solid black;
          padding: 25px;
          text-decoration: none;
          color: white;
       text-transform: uppercase;
    font-weight: bold;
    background: grey;
    
     &:hover {
    text-decoration: none; 
    color: yellow;
    background: darken(grey, 10%);
      }
       }
    

    As you can see, it is coded similarly to your github example. Any more questions, ask away!

提交回复
热议问题