1

I am getting crazy right now since i try to style my radio buttons for hours now and i cant reach my goal (im completely new to the world of css).

What i want to do is simple:

I want three big radiobuttons underneath each other centered in my div with labels vertically aligned to the buttons. something similar to this:

enter image description here

I have the following html:

<div class="answers">
    <label>
        <input type="radio" name="answers" value="male" /> All
    </label>
    <label>
        <input type="radio" name="answers" value="female" /> Name
    </label>
    <label>
        <input type="radio" name="answers" value="male" /> Vendor No.
    </label>
</div>

And the result is this:

enter image description here

I want much bigger buttons and much bigger text. i want the text to be to the right of the buttom with a little padding. i want all radio buttons to be centered. I tried many things but everything was just looking weird. Pls help me... i am beginning to hate css....

Mulgard
  • 9,877
  • 34
  • 129
  • 232

4 Answers4

2

The only reason to happen this is to have display: block somewhere in your css to radios:

input[type=radio] {
  display: block;
}
<div class="answers">
  <label>
    <input type="radio" name="answers" value="male" />All
  </label>
  <label>
    <input type="radio" name="answers" value="female" />Name
  </label>
  <label>
    <input type="radio" name="answers" value="male" />Vendor No.
  </label>
</div>

You can add display: block to second label using nth-child:

label:nth-child(2) {
  display: block;
}
<div class="answers">
  <label>
    <input type="radio" name="answers" value="male" />All
  </label>
  <label>
    <input type="radio" name="answers" value="female" />Name
  </label>
  <label>
    <input type="radio" name="answers" value="male" />Vendor No.
  </label>
</div>

References

nth-child

Alex Char
  • 32,879
  • 9
  • 49
  • 70
2

http://jsfiddle.net/6b888vp8/2/

Add display: block to the label in the answers div, and float left to the inputs. HTML has changed too

.answers label {
    display: block
}

.answers input[type="radio"] {
    float: left;
}

<div class="answers">
    <input type="radio" name="answers" value="male" /><label>All</label>
    <input type="radio" name="answers" value="female" /><label>Name</label>
    <input type="radio" name="answers" value="male" /><label>Vendor No.</label>
</div>
Pooshonk
  • 1,284
  • 2
  • 22
  • 49
2

You can use this CSS:

.answers label {
  display: block;
  font-size: 20px;
  line-height: 30px;
  margin: 0 auto;
  width: 150px;
}
.answers {
  width: 100%;
}
.answers input[type="radio"] {
  height: 30px;
  line-height: 30px;
  vertical-align: bottom;
  width: 30px;
}

JSFiddle: http://jsfiddle.net/ghorg12110/uqyfbjsb/

Magicprog.fr
  • 4,072
  • 4
  • 26
  • 35
  • with that css the text is still under the radio buttons. – Mulgard Jun 29 '15 at 15:05
  • @Mulgard updated my answer. Which browser are you using ? – Magicprog.fr Jun 29 '15 at 15:07
  • google chrome: if i use your code it does not look like in your jsfiddle. the text is not vertically aligned to the radio buttons – Mulgard Jun 29 '15 at 15:11
  • @Mulgard this can be due to the width of your anwers div. I've updated my answer with a class to set a width (but probably not). You've said you don't have any CSS right ? can you post your full HTML ? (I've just tried on chrome using a local file, and it's looks the same as the fiddle) – Magicprog.fr Jun 29 '15 at 15:16
  • pls add `.answers input[type="radio"] { float: left; width: 30px; height: 30px; }` to your js fiddle and see what happens. – Mulgard Jun 29 '15 at 15:20
  • @Mulgard updated the answer to include your input width correctly – Magicprog.fr Jun 29 '15 at 15:25
-1

This one worked for me:

 input[type="radio"]{
    width: 50px !important;
 }

Try it out and check if it works for you as well.

Anish Narayan
  • 72
  • 2
  • 8
  • `!important` is bad practice and should not be used by web developers unless absolutely necessary (or perhaps never, depending on who you ask). It exists for user stylesheets so that users may adjust the styling of a website (for example to aid accessibility). – Ben Dec 05 '21 at 01:14