Prevent wrapping of text below radio buttons

前端 未结 5 791
囚心锁ツ
囚心锁ツ 2020-12-15 19:53

The best way I could describe what I want is with this picture:

\"\"

How do I make it so the text aligns wi

5条回答
  •  执念已碎
    2020-12-15 20:26

    It's pretty simple, just turn your label element to display: block; and use margin-left for the label and float your radio button to the left

    Demo

    Demo 2 (Nothing fancy, just used multiple radio for the demonstration)

    input[type=radio] {
        float: left;
    }
    
    label {
        margin-left: 30px;
        display: block;
    }
    

    Just note that say if you are storing the radio with the labels in an li element, something like

    So make sure you self clear them by using something like

    .radiolist li:after {
        content: "";
        clear: both;
        display: table;
    }
    

    That will ensure that you are self clearing all the li elements, and about the :after psuedo, it is well supported in IE8 so nothing to worry about.

提交回复
热议问题