Hey friends today, let's see how to make useful custom radio buttons using HTML & CSS Only.
Now let's see about this project. When the page is loaded, a box with a question and answer choices appears. These are radio buttons. Generally, they're simple blue colored circle buttons , however today we see how to customize them manually in CSS with a nice animation too.
Do watch my video tutorial below for better understandings:
Now, let's see the source codes!
Paste the codes below in your HTML file:
<!-- Created by CodingPorium,2021. Visit https://youtube.com/c/CodingPorium for more tutorials with free source code -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Radio Buttons using CSS Only! | CodingPorium</title>
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
::selection{
background-color: gold;
color:black;
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body{
background-color: tomato;
color:black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container{
background:white;
padding:50px;
width:250px;
border-radius:5px;
}
.btn{
width: 100px;
height: 40px;
display: flex;
align-items: center;
margin-top: 1.2em;
padding: 0 0.5em;
}
.btn input{
position: relative;
cursor: pointer;
appearance: none;
-webkit-appearance: none;
}
.btn input::before,
.btn input::after{
content: '';
position: absolute;
width: 5px;
height: 5px;
border-radius: 50px;
}
.btn input:checked::before{
background: tomato;
transform: translate(-50%,-50%);
}
.btn input::after{
width: 10px;
height: 10px;
background: none;
border: 2px solid black;
border-radius: 50px;
transform: translate(-80%, -50%);
transition: all .4s;
}
.btn input:checked::after{
width: 100px;
height: 40px;
border-radius: 10px;
transform: translate(-15%, -50%);
z-index: 10;
}
.btn label{
margin-left: 0.5em;
cursor: pointer;
}
</style>
<body>
<div class="container">
<p>What type of developer are you?</p>
<div class="btn">
<input type="radio">
<label>Frontend</label>
</div>
<div class="btn">
<input type="radio">
<label>Backend</label>
</div>
</div>
</body>
</html>
And that's all for this tutorial. Thanks for reading and do subscribe to our YouTube channel to support us. Till the next one, goodbye!
Post a Comment