I have a button set, and would like to set the width of each button so they can be the same size (i.e. if I have 4 buttons of 25% each of the element)
Basically the site has a table on the left, and within that table I have 4 options. The way it is right now is it's not using 100% of the left column, so it looks bad. I'm looking to make the button set take 100% of the column, and each button to share 25% of the fixed space.
I've tried to .css('width') each button element but it's not making a difference.
My code looks like something like this:
<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>
You can do it like this:
$("#task-sort").buttonset().find('label').css('width', '25%');
After .buttonset()
your html looks like this:
<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>
Then you just need to set the width on those newly created <label>
elements to get the effect you want, you can try out a demo here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With