CSS。将文本居中放置在标签内,但忽略输入

时间:2017-05-22 08:16:20

标签: css drupal

所以我基本上有一个<label class="labelClass"> for="something"> <input id="inputID" class="inputClass" name="inputName" value="value" type="radio"> Some text inside the label. </label> 和这样的文字:

example

请注意,这只是label,并未用于任何其他方式。

所以我可以知道如何调用此inputmargin-right,但他们看起来像这样:

The problem

我已经尝试过:

  • padding
  • padding-right&amp; text-align:center
  • css

与以下.page-to-the-css label.something.option { margin-right:20px; padding-right:20px; text-align:center; } 示例类似:

radio

以及.page-to-the-css input.something.inputClass { margin-right:20px; padding-right:20px; text-align:center; } 按钮:

jquery

希望有人能帮我解决这个问题。

注意:除了javascript之外,我也无法触及csscss或其他任何内容,因此请将其保留在drupal

更新:目前的任何答案都没有,也不是VilleKoo的答案。

编辑:这是它发生的形式:form此网站为html,因此我无法访问code或遗憾的是我无法提供你们任何id。我希望这个问题可以解决。

3 个答案:

答案 0 :(得分:1)

这应该适合你。

label {
  display: block;
}

input { 
  display: inline-block; 
  margin-right: 0.5rem;
}
<label id="labelID" for="something">
    <input id="inputID" class="inputClass" name="inputName" value="value" type="radio">
    Some text inside the label.
</label>
<label id="labelID" for="something">
    <input id="inputID" class="inputClass" name="inputName" value="value" type="radio">
    Some text inside the label.
</label>

答案 1 :(得分:0)

看看我的例子,很容易

&#13;
&#13;
.labelClass {
	position: relative;
	display: block;
	text-align: center;
	padding-left: 20px;
}

.labelClass .inputClass {
	position: absolute;
	left: 0;
}
&#13;
<label class="labelClass" for="something">
    <input id="inputID" class="inputClass" name="inputName" value="value" type="radio">
    Some text inside the label.
</label>
&#13;
&#13;
&#13;

答案 2 :(得分:-1)

许多HTML元素都有默认的边距设置。您可以覆盖它并将其设置为0.在您的情况下,您想要在单选按钮上重置margin-right:

<input type="radio" name="beds" value="1" style="margin-right: 0" />

您可能希望将其添加到样式表中,以便它适用于所有单选按钮:

input[type="radio"] {
  margin-right: 0;
}