Align two inline-blocks left and right on same line

后端 未结 9 773
滥情空心
滥情空心 2020-11-27 11:50

How can I align two inline-blocks so that one is left and the other is right on the same line? Why is this so hard? Is there something like LaTeX\'s \\hfill that can consume

9条回答
  •  旧巷少年郎
    2020-11-27 12:27

    Displaying left middle and right of there parents. If you have more then 3 elements then use nth-child() for them.

    HTML sample:

    
        
    
    

    CSS sample:

    .nav-tabs{
      position: relative;
      padding-bottom: 50px;
    }
    
    .nav-tabs li {
      display: inline-block;  
      position: absolute;
      list-style: none;
    }
    .nav-tabs li:first-child{
      top: 0px;
      left: 0px;
    }
    .nav-tabs li:last-child{
      top: 0px;
      right: 0px;
    }
    .nav-tabs li:nth-child(2){
      top: 0px;
      left: 50%;
      transform: translate(-50%, 0%);
    }
    

提交回复
热议问题