Align two inline-blocks left and right on same line

后端 未结 9 800
滥情空心
滥情空心 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:23

    Taking advantage of @skip405's answer, I've made a Sass mixin for it:

    @mixin inline-block-lr($container,$left,$right){
        #{$container}{        
            text-align: justify; 
    
            &:after{
                content: '';
                display: inline-block;
                width: 100%;
                height: 0;
                font-size:0;
                line-height:0;
            }
        }
    
        #{$left} {
            display: inline-block;
            vertical-align: middle; 
        }
    
        #{$right} {
            display: inline-block;
            vertical-align: middle; 
        }
    }
    

    It accepts 3 parameters. The container, the left and the right element. For example, to fit the question, you could use it like this:

    @include inline-block-lr('header', 'h1', 'nav');
    

提交回复
热议问题