How can I get input radio elements to horizontally align?

后端 未结 4 1757
难免孤独
难免孤独 2020-12-31 01:34

I want these radio inputs to stretch across the screen, rather than one beneath the other:

HTML



        
相关标签:
4条回答
  • 2020-12-31 02:14

    In your case, you just need to remove the line breaks (<br> tags) between the elements - input elements are inline-block by default (in Chrome at least). (updated example).

    <input type="radio" name="editList" value="always">Always
    <input type="radio" name="editList" value="never">Never
    <input type="radio" name="editList" value="costChange">Cost Change
    

    I'd suggest using <label> elements, though. In doing so, clicking on the label will check the element too. Either associate the <label>'s for attribute with the <input>'s id: (example)

    <input type="radio" name="editList" id="always" value="always"/>
    <label for="always">Always</label>
    
    <input type="radio" name="editList" id="never" value="never"/>
    <label for="never">Never</label>
    
    <input type="radio" name="editList" id="change" value="costChange"/>
    <label for="change">Cost Change</label>
    

    ..or wrap the <label> elements around the <input> elements directly: (example)

    <label>
        <input type="radio" name="editList" value="always"/>Always
    </label>
    <label>
        <input type="radio" name="editList" value="never"/>Never
    </label>
    <label>
        <input type="radio" name="editList" value="costChange"/>Cost Change
    </label>
    

    You can also get fancy and use the :checked pseudo class.

    0 讨论(0)
  • 2020-12-31 02:14

    Here is updated Fiddle

    Simply remove </br> between input radio's

    <div class="clearBoth"></div>
    <input type="radio" name="editList" value="always">Always
    <input type="radio" name="editList" value="never">Never
    <input type="radio" name="editList" value="costChange">Cost Change
    <div class="clearBoth"></div>
    
    0 讨论(0)
  • 2020-12-31 02:15

    This also works like a charm

    <form>
        <label class="radio-inline">
          <input type="radio" name="optradio" checked>Option 1
        </label>
        <label class="radio-inline">
          <input type="radio" name="optradio">Option 2
        </label>
        <label class="radio-inline">
          <input type="radio" name="optradio">Option 3
        </label>
      </form>

    0 讨论(0)
  • 2020-12-31 02:28

    To get your radio button to list horizontally , just add

    RepeatDirection="Horizontal"

    to your .aspx file where the asp:radiobuttonlist is being declared.

    0 讨论(0)
提交回复
热议问题