jqueryui buttonset()上的按钮之间的差距

Bri*_*ian 9 jquery jquery-ui

我遇到了一个有趣的现象,我的buttonset()所有按钮之间都有差距.显然我希望他们像在jquery演示中一样.

我的代码很有库存

HTML

<div style="float:right;" id="filter-button-bar">
    <input type="radio" id="it_button" name="radio" class="filter-button" /><label for="it_button">Information</label>
     <input type="radio" id="rev_button" name="radio" class="filter-button" /><label for="rev_button">Revenue</label>
    <input type="radio" id="ent_button" name="radio" class="filter-button" /><label for="ent_button">Entertainment</label>
    <input type="radio" id="sec_button" name="radio" class="filter-button" /><label for="sec_button">Security</label>
    <input type="radio" id="asst_button" name="radio" class="filter-button" /><label for="asst_button">Assistants</label>
    <input type="radio" id="all_button" name="radio"  class="filter-button" checked="checked"/><label for="all_button">All</label>
</div>
Run Code Online (Sandbox Code Playgroud)

JS

$(function() {
    $( "#filter-button-bar" ).buttonset();
    $( ".filter-button" ).button({
        icons: {
            primary: "ui-icon-search"
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

截图

令人讨厌的是,当放入jsfiddle时,一切看起来都很棒.的jsfiddle

Rob*_*b W 15

删除这些按钮之间的空格.这将解决您的问题:

<input type="radio" id="it_button" name="radio" class="filter-button" /><label for="it_button">Information</label><input type="radio" id="rev_button" name="radio" class="filter-button" /><label for="rev_button">Revenue</label><input type="radio" id="ent_button" name="radio" class="filter-button" /><label for="ent_button">Entertainment</label><input type="radio" id="sec_b Et cetera
Run Code Online (Sandbox Code Playgroud)

HTML源代码中的空格通常在HTML中被忽略,除了少数情况:

  • CSS:white-space: pre,, pre-wrap...(和<pre>标签)
  • 内联元素之间.

此更新后,您的代码似乎不太可读.如果您不想将整个代码放在一行,则可以在HTML标记内安全地添加换行符.