Div boxes not aligning properly using inline-block

前端 未结 2 1732
难免孤独
难免孤独 2021-02-18 18:11

I have some very simple code which works perfect for what look I\'m trying to achieve. I have two divs which are displayed as \"boxes\" which are contained within an outer div w

相关标签:
2条回答
  • 2021-02-18 18:50

    Since the boxes are already inline-block you can add vertical-align: top to the .box style.

    0 讨论(0)
  • 2021-02-18 18:53

    .box {
      display: inline-block;
      border: solid 1px;
      vertical-align: top;
      width: 40%;
    }
    <div id="boxContainer">
      <div class="box">
        <h3>BOX 1</h3>
        <p>Lorem ipsum dolor sit amet, altera interesset pri an. Et aeque interpretaris vel, at quo summo deleniti disputationi. Eu inimicus splendide duo, soleat intellegam ut per. Sint impedit recusabo ex vix, aliquid adipisci consequat no ius. Eu possim consequat eum, sea cu quaeque impedit, est fuisset accusamus definiebas ad.</p>
      </div>
    
      <div class="box">
        <h3>BOX 2</h3>
        <p>Viris eruditi consectetuer ei mea, eu nulla ridens officiis duo. In atomorum forensibus abhorreant quo, id nec aperiam dissentiet.</p>
      </div>
    </div>

    You can use the vertical-align CSS property.

    It has effect only on inline, and inline-block elements.

    This is a great reference on vertical-align.

    0 讨论(0)
提交回复
热议问题