简体   繁体   English

无法将单选按钮及其标签对齐一行

[英]Unable to align radio buttons and their labels in one line

Below is a snippet of the appearance of current page. 以下是当前页面外观的摘要。

Radio buttons and their labels not in single line 单选按钮及其标签不在一行

Below is the piece of code is being used. 下面是正在使用的代码段。 (JSP) (JSP)

 <div class="leftFormComp" style="width: 100%;"> <label class="inputLabel" for="ext-comp-1045"> <span class="required">*</span><fmt:message key="registration.agreement"/> </label> <div id="x-form-el-ext-comp-1045" class="x-form-element" style="padding-left: 8px;"> <div id="ext-comp-1045" class=" x-form-checklist" style="width: 344px; height: auto;"> <div class="x-form-cb-li x-form-cb-li-h" style="padding-bottom: 5px"> <input id="termsAgree-Y" class="x-form-field" type="radio" value="Y" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-Y"><fmt:message key="registration.yes"/></label> </div> <div class="x-form-cb-li x-form-cb-li-h"> <input id="termsAgree-N" class="x-form-field" type="radio" value="N" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-N"><fmt:message key="registration.no"/></label> </div> </div> </div> </div> 

I have tried using inline styling like 我曾尝试使用内联样式

display: inline!important;

with input and label tags but nothing is working. 输入和标签标签,但没有任何效果。

While checking in Chrome Developer mode, I came across an extra attribute that was getting appended in the input tags of both the radio buttons and I am unable to figure out from where it is coming. 在Chrome开发者模式下进行检查时,我遇到了一个额外的属性,该属性已附加到两个单选按钮的输入标签中,因此无法确定它的出处。

element.style {
    display: block;
}

Can someone please suggest way to override all existing stylings that are getting implemented on this element, so as to bring the radio buttons and their labels in one line. 有人可以建议一种方法来覆盖在此元素上实现的所有现有样式,以便将单选按钮及其标签放在一行中。 I am new to front-end part, so please help me out. 我是前端部分的新手,请帮助我。 Also, help me find the origin of this styling (Can it be found using Chrome Developer tool) 另外,请帮助我找到此样式的来源(可以使用Chrome Developer工具找到)

Just write after fmt 在fmt之后写

<label class="x-form-cb-label" for="termsAgree-Y">
      <fmt:message key="registration.yes" />Yes
</label>

i think it will work. 我认为它将起作用。

You did that wrong. 你做错了 You missed the right name. 您错过了正确的名字。

change it into display:inline-block; 更改为display:inline-block;

In the example below I used it onto the div 's. 在下面的示例中,我将其用于div But this css will work on every element you want. 但这CSS可以在您想要的每个元素上使用。

 div{display:inline-block;} 
 <div class="leftFormComp" style="width: 100%;"> <label class="inputLabel" for="ext-comp-1045"> <span class="required">* Subject</span><fmt:message key="registration.agreement"/> </label> <div id="x-form-el-ext-comp-1045" class="x-form-element" style="padding-left: 8px;"> <div id="ext-comp-1045" class=" x-form-checklist" style="width: 344px; height: auto;"> <div class="x-form-cb-li x-form-cb-li-h" style="padding-bottom: 5px"> <input id="termsAgree-Y" class="x-form-field" type="radio" value="Y" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-Y"><fmt:message key="registration.yes"/>Yes</label> </div> <div class="x-form-cb-li x-form-cb-li-h"> <input id="termsAgree-N" class="x-form-field" type="radio" value="N" name="termsAgree"> <label class="x-form-cb-label" for="termsAgree-N"><fmt:message key="registration.no"/>No</label> </div> </div> </div> </div> 

An easy way to fix this would be to simply add "float: left" to the radio buttons. 解决此问题的一种简单方法是在单选按钮上简单地添加“ float:left”。

<input style="float:left" id="termsAgree-N" class="x-form-field" type="radio" value="N" name="termsAgree"> 
<label class="x-form-cb-label" for="termsAgree-N"><fmt:message key="registration.no"/></label>

This means you don't need to worry about changing to display:inline-block . 这意味着您无需担心更改为display:inline-block This snippet demonstrates that it works even when the radio buttons are set to display:block . 此代码段演示了即使单选按钮设置为display:block ,它也可以工作。

 <div> <input type="radio" style="display:block;" /> <label>without float:left</label> </div><br/> </br/> <div> <input type="radio" style="display:block; float:left" /> <label>with float:left</label> </div> 

This is a picture of before and after: 这是之前和之后的图片:

在此处输入图片说明

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

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