Vertically align inline block elements

試著忘記壹切 提交于 2019-11-28 13:39:06

You can take a look here, I've made it from scratch...

Demo

So what I did here is, I've used display: table; for the container element and am using display: table-cell; for the child div and as the child div are now table cells, I used vertical-align: top; so that the elements align to the top in those cells

section > div {
    vertical-align: top;
    display: table-cell;
    width: 33%;
    text-align: center;
}

section {
    display: table;
    width: 100%;
}

HTML

<h4>Additional Info</h4>
<section>
    <div>
        <input type="checkbox" /><br />
        <label for="">I've got a valid certificate permits</label>
    </div>
    <div>
        <input type="checkbox" /><br />
        <label for="">I've got a valid certificate</label>
    </div>
    <div>
        <input type="checkbox" /><br />
        <label for="">I certificate</label>
    </div>
</section>

Why not use a simple float to get rid of the remaining 'white space':

.additional-info div {
  width: 32.6%;
  /*display: inline-block;*/
  text-align: center;
  float: left;
}

jsFiddle

I have done an inline-block level based on what you said above. Using a set width on the parent div and then child elements forces the items to stack rather than appear in a horizontal list.

<div style="display:inline-block; width:150px;">
<div style="display:inline-block; width:150px;"><input /></div>
    <div style="display:inline-block; width:150px;"><input /></div>
    <div style="display:inline-block; width:150px;"><input /></div>
    <div style="display:inline-block; width:150px;"><input /></div>
</div>

Worth trying to see if it works for your form?

(I know I've done it here as inline-style, but this is just as an example I quickly put together)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!