简体   繁体   中英

HTML/CSS align 2 elements to 1 element e.g. 2 inputs with one label

Here's a picture of what I wanna achieve :

在此处输入图片说明

How to align Input 2 with Input 1? It bugs my mind how difficult it seems to achieve something so simple. The whole thing needs to be web responsive, obviously. Also, I don't wanna use tables.

<form>
  <div class="field">
    <label>Label</label>
    <input id="Input 1" type="text" />
  </div>
  <div class="field">
    <input id="Input 2" type="text" />
  </div>
</form>

Float can do this easily. Make sure the bottom margin is big enough to push the second input:

 label { float:left; margin:5px 0 10px; } input { margin:2px 5px; }
 <form> <div class="field"> <label>Label</label> <input id="Input 1" type="text" > </div> <div class="field"> <input id="Input 2" type="text" > </div> </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM