简体   繁体   English

有序列表编号和标签未对齐

[英]ordered list number and label misaligned

I have a label and an input in an ol like this 我有这样的labelinputol

<ol>
  <li>
    <label for="testing" style="display:inline-block;width:200px;">
      <!-- Content Here -->
    </label>
    <input type="checkbox" id="testing" name="test" value="" />
  </li>
</ol>

If I add width to my label , this is the result I get 如果我在label加上width就是我得到的结果

As you can see, the first line in my label (starting with the first word Donex ) is not aligned with the number 1 of my list. 如您所见, label的第一行(以第一个单词Donex )与列表中的数字1不一致。 I want the text of my label to start on the same line as the number of my list. 我希望标签的文本与列表编号在同一行开头。

将标签样式设置为vertical-align:top;

Please Try this : 请尝试这个:

<ol>
    <li ><label for="testing" style="width:200px;display:inline-block;vertical-align:top">Donec vitae sem et purus luctus venenatis. In hac habitasse platea dictumst. Vivamus posuere fermentum dapibus.</label> <input  type="checkbox" name="testing" value="" /></li>
</ol>

Run on Fiddle . Fiddle上运行。 Hope it will be your expected output. 希望这将是您的预期输出。

is this what look like demo 1 or this demo 2 这是演示1还是演示2

html html

<ol>
    <li><label for="testing">Donec vitae sem et purus luctus venenatis. In hac habitasse platea dictumst. Vivamus posuere fermentum dapibus.</label> <input type="checkbox" name="testing" value="" /></li>
</ol>

added css for demo 1 为演示1添加了CSS

ol li label {
    display:block;
    width:200px;
}

added css for demo 2 为演示2添加了CSS

ol li label {
    float:left;
    width:200px;
}

hope this help 希望这个帮助

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

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