简体   繁体   English

将标签与复选框水平对齐

[英]Align label with Checkbox horizontally

I'm new in this forum and i found a problem i really don't know how to resolve. 我是这个论坛的新手,我发现一个问题,我真的不知道该如何解决。

I have a table with a checkbox list. 我有一张带有复选框列表的表。 And everything is ok. 一切都很好。 i used: 我用了:

    display:inline-block;

And the label look align but in small devices like mobile phones i would like instead to appear: 而且标签看起来对齐,但是我希望在像移动电话这样的小型设备中显示:

"[] Other                   
 Unknown"                                 

I would like to align the label like this: 我想像这样对齐标签:

 "[] Other
     Unknown"

How could i align the label to appear like that? 我如何对齐标签使其看起来像这样?

https://jsfiddle.net/apastorts/d9efnf08/ https://jsfiddle.net/apastorts/d9efnf08/

You just have to add CSS like td.cstm-cls {display: flex;} 您只需要添加CSS,例如td.cstm-cls {display: flex;}

 body{width:40%;} label{display:inline;font-size:11px;} td.cstm-cls { display: flex; } 
  <table class='table'> <thead> <h3>Crane Brand</h3> </thead> <tbody> <tr> <td><input type="checkbox" name="craneBrands[]" value='Demag'><label>Demag</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Kone'><label>Kone</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Starluff'><label>Starluff</label></input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Gis'><label>Gis</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='JDN Monocrane'><label>JDN Monocrane</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Monosteel'><label>Monosteel</label></input></input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Litfking'><label>Litfking</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Atlas Copco'><label>Atlas Copco</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Ingersoll Rand'><label>Ingersoll Rand</label></input></input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Hitachi'><label>Hitachi</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Kito'><label>Kito</label></input></td> <td class="cstm-cls"><input type="checkbox" name="craneBrands[]" value='Other/Unknown'><label>Other / Unknown</label></input></td> </tr> </tbody> </table> 

Change your style like following code snippet (changes in CSS) 像下面的代码片段一样更改样式(CSS中的更改)

 body{width:40%;} td{padding:0px} label{display:inline;font-size:11px;display:flex;word-wrap: break-word;} input[type=checkbox]{float:left;padding:0px} 
  <table class='table'> <thead> <h3>Crane Brand</h3> </thead> <tbody> <tr> <td><input type="checkbox" name="craneBrands[]" value='Demag'><label>Demag</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Kone'><label>Kone</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Starluff'><label>Starluff</label></input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Gis'><label>Gis</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='JDN Monocrane'><label>JDN Monocrane</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Monosteel'><label>Monosteel</label></input></input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Litfking'><label>Litfking</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Atlas Copco'><label>Atlas Copco</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Ingersoll Rand'><label>Ingersoll Rand</label></input></input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Hitachi'><label>Hitachi</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Kito'><label>Kito</label></input></td> <td><input type="checkbox" name="craneBrands[]" value='Other/Unknown'><label>Other /Unknown</label></input></td> </tr> </tbody> </table> 

I have solve your issue. 我已经解决了你的问题。 Please Run the below snippet , 请运行以下代码段,

 label { display: inline-block; font-size: 11px; } .table td input, .table td label { float: left; } .table td input { margin: 0px 5px 0; } 
 <table class='table'> <thead> <h3>Crane Brand</h3> </thead> <tbody> <tr> <td><input type="checkbox" name="craneBrands[]" value='Demag'> <label>Demag</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='Kone'> <label>Kone</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='Starluff'> <label>Starluff</label> </input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Gis'> <label>Gis</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='JDN Monocrane'> <label>JDN Monocrane</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='Monosteel'> <label>Monosteel</label> </input> </input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Litfking'> <label>Litfking</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='Atlas Copco'> <label>Atlas Copco</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='Ingersoll Rand'> <label>Ingersoll Rand</label> </input> </input> </tr> <tr> <td><input type="checkbox" name="craneBrands[]" value='Hitachi'> <label>Hitachi</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='Kito'> <label>Kito</label> </input></td> <td><input type="checkbox" name="craneBrands[]" value='Other/Unknown'> <label>Other /Unknown</label> </input></td> </tr> </tbody> </table> 

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

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