Making Chrome-like tab resize with pure css

后端 未结 3 955
囚心锁ツ
囚心锁ツ 2021-01-13 23:34

I am trying to create tabs that resize a bit similar to how Chrome tabs does. But I am not sure how and if it is even possible to do without JavaScript.

I don\'t ca

3条回答
  •  情话喂你
    2021-01-14 00:23

    You can get pretty close to Chrome's actual behavior with the flexbox...

    body {
      font: 12px/130% 'Lucida Sans', 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; 
    }
    
    ul {
      background-color: #eee;
      display: -webkit-box;
      padding: 10px 10px 0 10px;
    }
    
    
    ul li {
      -webkit-box-flex: 1;
      background: #ffffd;
      padding: 10px 15px 6px 15px;
      white-space: nowrap;
      overflow: hidden;
      max-width: 150px;
      min-width: 50px;
      border: solid #ccc 1px;
      border-bottom: none;
      border-radius: 5px 5px 0 0;
      text-overflow: ellipsis;  
    }
    

    http://jsfiddle.net/a656n/

    ​However, your specs are impossible in CSS only. I'd also suggest that keeping the active tab 'unshrunk' breaks conventions because your tabs will change position every time you click on them.

提交回复
热议问题