我希望我的标签右对齐,但它弄乱了我的单选按钮。我需要按钮和标签更接近,这两个选项应该更接近。我试过很多方法,但似乎都做不对。表单的当前外观如下所示:

任何帮助都将不胜感激。
下面是单选按钮的HTML外观
#wrapper {
width: 50%;
margin-left:4%;
}
div#formcol1 {
float:left;
width: 100%;
line-height: 1em;
padding-bottom: 15px;
}
label {
margin-right: .3em;
width: 6.3em; /* I made this deliberately wide – come up with your own optimal width */
margin-top: 10px;
display: inline-block; /* width will not work for “inline” elements such as “label”. Therefore we need to set it to “inline-block” */
text-align: right;
}
#formcol1 li {
list-style:none;
line-height: 1.5;
margin: 5px
}
input[type=text]{
width: 40%;
padding: 0 20px;
}
input[type=radio] {
margin-top: 10px;
margin-left: 0px;
margin-right: 5px;
}
/* adds highlights to current fields */
input[type=text]:focus, textarea:focus {
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 5px solid rgba(81, 203, 238, 1);<div id="multchoice">
<fieldset>
<legend>Type of Presentation</legend>
<p><span><input value = "1" id = "TypeofPres_lec" name="p-type" type = "radio" />
<label for = "TypeofPres_lec">Lecture</label></span>
<span><input value = "2" id = "TypeofPres_lab" name="p-type" type = "radio" />
<label for = "TypeofPres_lab">Lab</label></span></p>
</fieldset>
<p class="submit-button">
<input type="submit" value="Submit your proposal" /></p>
</div> <!-- end of multchoice div -->
发布于 2021-03-26 07:08:07
尝试将您的输入放在标签标记内。
#wrapper {
width: 50%;
margin-left: 4%;
}
div#formcol1 {
float: left;
width: 100%;
line-height: 1em;
padding-bottom: 15px;
}
label {
margin-right: .3em;
width: 6.3em;
/* I made this deliberately wide – come up with your own optimal width */
margin-top: 10px;
display: inline-block;
/* width will not work for “inline” elements such as “label”. Therefore we need to set it to “inline-block” */
text-align: right;
}
#formcol1 li {
list-style: none;
line-height: 1.5;
margin: 5px
}
input[type=text] {
width: 40%;
padding: 0 20px;
}
input[type=radio] {
margin-top: 10px;
margin-left: 0px;
margin-right: 5px;
}
/* adds highlights to current fields */
input[type=text]:focus,
textarea:focus {
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
padding: 3px 0px 3px 3px;
margin: 5px 1px 3px 0px;
border: 5px solid rgba(81, 203, 238, 1);<div id="multchoice">
<fieldset>
<legend>Type of Presentation</legend>
<p><span>
<label for = "TypeofPres_lec">
<input value = "1" id = "TypeofPres_lec" name="p-type" type = "radio" /> Lecture
</label>
<label for = "TypeofPres_lab">
<input value = "2" id = "TypeofPres_lab" name="p-type" type = "radio" /> Lab
</label>
</span></p>
</fieldset>
<p class="submit-button">
<input type="submit" value="Submit your proposal" /></p>
https://stackoverflow.com/questions/66808791
复制相似问题