Aligning elements left and center with flexbox

前端 未结 7 440
眼角桃花
眼角桃花 2020-11-29 01:12

I\'m using flexbox to align my child elements. What I\'d like to do is center one element and leave the other aligned to the very left. Normally I would just set the left el

相关标签:
7条回答
  • 2020-11-29 02:12

    I have another solution. In my opinion, Adding an empty block to the center element is fine but code-wise it bit ugly. My solution for this is below

        <div id="parent">
          <span id="left">Left</span>
          <span id="center">Center</span>
        </div>
    
       #parent {
          display: flex;    
       }
    
       #left {
          flex:1;
       } 
    
       #center {
          flex:1;
       } 
    
       #parent:after {
          flex:1;
       }
    
    0 讨论(0)
提交回复
热议问题