Design Radio Button with html and css

Mahabubur Rahman
1
At present the design is an important part of web programming. So we have to design properly. We often work with form. Some time we use radio in our web form. In general radio look like as below
But we want to make it different from above. So we have to design it with CSS(Cascading Style Sheet).
First of all we write a basic radio in HTML.
<div class="design">
<input type="radio" name="d1" id="radio11">
<label for="radio11">Radio11</label>
<input type="radio" name="d1" id="radio12">
<label for="radio12">Radio12</label>
</div> 
Now we will design it with CSS . First we hide radio inputs and design its label properly.
.design1 input[type='radio']{
display: none
}
.design1 label{
display: inline-block;
cursor: pointer;
position: relative;
padding-left:20px;
margin-right: 10px;
font-size: 100%;
}
After write the above css the radio button look like below.

Now we will fixed the box before label. It well be as below css code.
.design1 label:before{
content: "";
height: 15px;
width: 15px;
border: 1px solid #999;
margin-right: 10px;
display: inline-block;
position: absolute;
left: 0;
}
.design1 label:before{
border-radius: 4px;
}
After write the above code the radio button look like as below.

Now I will write what we wand show after clicking/checking the radio button. The code for checked radio button as 
.design1 input[type='radio']:checked+label:before{
content: '\2713';
line-height: 18px;
text-shadow: 0 0px 1px #797979;
}
After finishing our design for radio button the radio button group look like as below image.
For any question on this topics please write your question/comment on comment area below.
Tags

Post a Comment

1Comments
  1. Have you tried em, instead of px....so it is a little bit fluid for different browser settings..

    ReplyDelete
Post a Comment