简体   繁体   English

如何将标签与复选框对齐

[英]How to align a label with checkbox

 span{ text-align: justify; } 
 <input type="checkbox" name="type"><span>Excessive Reinforcement</span><br> 

I want to align the label for excessive reinforcement checkbox like image2 我想对齐标签,以确保像image2这样的过度加固复选框

For example 例如

Thanks in advance 提前致谢

First of all use <label> instead of <span> . 首先使用<label>而不是<span>

If we use bootstrap we generally manage this with classes but here if we talk about custom css this can be a solution. 如果我们使用引导程序,则通常使用类来管理它,但是在这里,如果我们谈论自定义css,这可以是一个解决方案。

 label{ text-align: justify; float: left; line-height: 20px; } input{ float:left; } 
 <input type="checkbox" id="check" name="type"><label for="check">Excessive<br>Reinforcement</label><br> 

Above i added id in checkbox and for in label so that checkbox will be selected on click of label also. 我在上面添加id的复选框,并for在标签中,这样复选框将标签上也点击进行选择。

If you can change the HTML 如果可以更改HTML

The best and new method to use checkbox is 最好和新的使用方法是

<label><input type="checkbox" name="type">Excessive Reinforcement</label>

This is one way of doing it: 这是一种实现方式:

<label for="type-1">
   <input id="type=1" type="checkbox" name="type"> Excessive Reinforcement
</label><br>

When using input elements, you should always provide a label with the for attribute assigned the id of the input element. 使用输入元素时,应始终为标签提供for属性,并为其分配输入元素的ID。 And also make sure the input element ids are unique. 还要确保输入元素的ID是唯一的。

 span { text-align: justify; } .make-table { display: table-cell; /* make it behave like table-cell. so that they fall beside each other. */ } 
 <div class="any-class"> <label><span class="make-table"><input type="checkbox" name="type"></span> <span class="make-table">Excessive<br> Reinforcement</span> </label> </div> <hr> <div style="color:red">Wrap it inside any-class and align as you want. <br>I added LABEL tag, so that, even if your user clicks on the text, the checkbox will work.</div> 

Make this simple change! 进行简单的更改!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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