简体   繁体   中英

How to position two elements in <label> side by side

我希望“SSSS”位于“XXXXXX”文本的右侧

 <label for="checkbox6">XXXXXX <div style="padding-left: 9.5%;padding-right: 45%;padding-bottom:1.5%"><input class="form-control" name="quantum" type="number" min="1" placeholder="SSSS" required></div> </label>

I want the "SSSS" to be on the right side of the "XXXXXX" text

Issues with your snippet:

  • Do not nest your input inside the label.
  • Your for attribute does not match the input element's name attribute.

 <div> <label for="myInput">XXXXX</label> <input name="myInput" placeholder="SSSS"/> </div>

Just add display:flex to <label> like so:

label {
  display: flex;
}

Here is the JSFiddle demo

Also note I removed the original padding styles u provided in ur code.

 <div> <label for="checkbox6">XXXXXX</label> <input class="form-control" name="quantum" type="number" min="1" placeholder="SSSS" required> </div>

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