How can I let a div fill 100% width if no other elements are beside it?

后端 未结 3 1639
小鲜肉
小鲜肉 2021-02-18 13:00

I have simple markup like this (a tab menu):

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-18 13:41

    Depending on what browsers you need to support, you may be able to use flexbox:

    $('.tab').click(function() {
      $(this).css('display', 'none');
    });
    .container {
      display: flex;
    }
    
    .tab {
      border: 1px solid black;
      padding: 5px;
      flex: 1;
      margin: 5px;
    }

    Click a tab to remove it

    Tab 1
    Tab 2
    Tab 3

提交回复
热议问题