4

ボタン セットがあり、各ボタンの幅を同じサイズに設定したい (つまり、各要素の 25% のボタンが 4 つある場合)

基本的にサイトの左側にテーブルがあり、そのテーブル内に 4 つのオプションがあります。今のままでは、左側の列を 100% 使用していないため、見栄えが悪くなります。ボタン セットが列の 100% を占有し、各ボタンが固定スペースの 25% を共有するようにしようとしています。

各ボタン要素を .css('width') にしようとしましたが、違いはありません。

私のコードは次のようになります。

 <script type='text/javascript'>
  $( function() { $("#task-sort").buttonset();   } );
 </script>

 <div id='task-sort'>
  <input type='radio' name='task-sort' id='sort_all' checked><label for='sort_all'>All</label>
  <input type='radio' name='task-sort' id='sort_inc'><label for='sort_inc'>Incomplete</label>
  <input type='radio' name='task-sort' id='sort_com'><label for='sort_com'>Completed</label>
 </div>
4

1 に答える 1

10

次のように実行できます。

$("#task-sort").buttonset().find('label').css('width', '25%');​​​​​​​​​​​​​​​​

.buttonset()あなたのhtmlが次のようになった後:

<div id="task-sort" class="ui-buttonset">
  <input type="radio" name="task-sort" id="sort_all" checked="" class="ui-helper-hidden-accessible">
  <label for="sort_all" class="ui-state-active ui-button ui-widget ui-state-default ui-button-text-only ui-corner-left" aria-pressed="true" role="button" aria-disabled="false"><span class="ui-button-text">All</span></label>
  <input type="radio" name="task-sort" id="sort_inc" class="ui-helper-hidden-accessible">
  <label for="sort_inc" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Incomplete</span></label>
  <input type="radio" name="task-sort" id="sort_com" class="ui-helper-hidden-accessible">
  <label for="sort_com" aria-pressed="false" class="ui-button ui-widget ui-state-default ui-button-text-only ui-corner-right" role="button" aria-disabled="false"><span class="ui-button-text">Completed</span></label>
 </div>

次に、新しく作成した<label>要素に幅を設定して、必要な効果を得る必要があります。ここでデモを試すことができます

于 2010-06-18T22:01:20.000 に答える