How to achieve exact radio button style design? - html

I am sharing an image of button can some one help with the html css to achieve exact design.
Normal state of radio button
On hover style or Checked state

html code:
<div class="radio-button">
<input class="radio-button__input" type="radio" name="" id="btn">
<label class="radio-button__label" for="btn">Text here</label>
</div>
css code:
.radio-button{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.radio-button__input{
display: none;
}
.radio-button__label{
border: .1em solid gray;
font-size: 48px;
padding: .5em;
border-radius: 2em;
}
.radio-button__input:hover + .radio-button__label, .radio-button__input:checked + .radio-button__label{
background-color: mediumvioletred;
}
styling on .radio-button is only to center it so you can delete it if you need to
if you want the transition to be smooth just add transition on .radio-button__label

*,
*::before,
*::after {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
font-family: "Roboto", sans-serif;
}
.radio input {
display: none;
}
.radio-box {
padding: 15px 30px 12px;
border-radius: 50px;
color: #868aa8;
border: 2px solid #868aa8;
text-transform: uppercase;
font-size: 34px;
letter-spacing: 0.5px;
cursor: pointer;
transition: all 0.3s linear;
display: inline-block;
margin: 0 5px;
}
.radio input:checked + .radio-box,
.radio-box:hover {
color: #fff;
background-color: #ea0b5b;
border-color: #ea0b5b;
}
<label class="radio">
<input type="radio" name="time">
<span class="radio-box">5:30 PM</span>
</label>

Related

Content Moves on Opening Select Dropdown

I need help with the Select Dropdown. It moves the content (Hello World) when opened. I have used Radio Input to select the specfic option when performing a Search. If there is any other better solution for this type of functionality, please assist.
HTML
<span class="dropdown-el">
<input type="radio" name="sortType" value="Relevance" checked="checked" id="sort-relevance"><label for="sort-relevance">Relevance</label>
<input type="radio" name="sortType" value="Popularity" id="sort-best"><label for="sort-best">Product Popularity</label>
<input type="radio" name="sortType" value="PriceIncreasing" id="sort-low"><label for="sort-low">Price Low to High</label>
<input type="radio" name="sortType" value="PriceDecreasing" id="sort-high"><label for="sort-high">Price High to Low</label>
<input type="radio" name="sortType" value="ProductBrand" id="sort-brand"><label for="sort-brand">Product Brand</label>
<input type="radio" name="sortType" value="ProductName" id="sort-name"><label for="sort-name">Product Name</label>
</span>
<h1> Hello World</h1>
CSS
body {
text-align: center;
background: #ebf4fb;
min-height: 95vh;
margin: 0;
padding: 0;
border-bottom: 5vh solid #3694d7;
font-family: "Myriad Pro", "Arial", sans;
font-size: 24px;
}
.dropdown-el {
margin-top: 20vh;
min-width: 12em;
position: relative;
display: inline-block;
margin-right: 1em;
min-height: 2em;
max-height: 2em;
overflow: hidden;
top: 0.5em;
cursor: pointer;
text-align: left;
white-space: nowrap;
color: #444;
outline: none;
border: 0.06em solid transparent;
border-radius: 1em;
background-color: #cde4f5;
transition: 0.3s all ease-in-out;
}
.dropdown-el input:focus + label {
background: #def;
}
.dropdown-el input {
width: 1px;
height: 1px;
display: inline-block;
position: absolute;
opacity: 0.01;
}
.dropdown-el label {
border-top: 0.06em solid #d9d9d9;
display: block;
height: 2em;
line-height: 2em;
padding-left: 1em;
padding-right: 3em;
cursor: pointer;
position: relative;
transition: 0.3s color ease-in-out;
}
.dropdown-el label:nth-child(2) {
margin-top: 2em;
border-top: 0.06em solid #d9d9d9;
}
.dropdown-el input:checked + label {
display: block;
border-top: none;
position: absolute;
top: 0;
width: 100%;
}
.dropdown-el input:checked + label:nth-child(2) {
margin-top: 0;
position: relative;
}
.dropdown-el::after {
content: "";
position: absolute;
right: 0.8em;
top: 0.9em;
border: 0.3em solid #3694d7;
border-color: #3694d7 transparent transparent transparent;
transition: 0.4s all ease-in-out;
}
.dropdown-el.expanded {
border: 0.06em solid #3694d7;
background: #fff;
border-radius: 0.25em;
padding: 0;
box-shadow: rgba(0, 0, 0, 0.1) 3px 3px 5px 0px;
max-height: 15em;
}
.dropdown-el.expanded label {
border-top: 0.06em solid #d9d9d9;
}
.dropdown-el.expanded label:hover {
color: #3694d7;
}
.dropdown-el.expanded input:checked + label {
color: #3694d7;
}
.dropdown-el.expanded::after {
transform: rotate(-180deg);
top: 0.55em;
}
JQuery
$('.dropdown-el').click(function(e) {
e.preventDefault();
e.stopPropagation();
$(this).toggleClass('expanded');
$('#'+$(e.target).attr('for')).prop('checked',true);
});
$(document).click(function() {
$('.dropdown-el').removeClass('expanded');
});
https://codepen.io/libsys/pen/bGKomaE
Please assist.

Is there a way make this html outline style different?

Smiley Face
Im working on a customer survey page and this is currently what i have. Those are images as radio buttons. The problem is when it's checked, it's ugly with the red square outline. Is there a way to make it circular soft glow? This is the code. I've search up the outline style but they're mostly dotted or double lines style and that's not what im looking for. Any help is appreciated.
<label style="display: inline-block;">
<h3>Dissatisfied</h3>
<input type="radio" ngModel name="smiley" value="Dissatisfied">
<img src="..\assets\images\smiley_2_62x62.png">
</label>
Full css for the radio and form.
[type=radio] {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
/* IMAGE STYLES */
[type=radio] + img {
cursor: pointer;
}
/ * CHECKED STYLES */
[type=radio]:checked + img {
outline: 2px solid #f00;
}
This will change the border to be round like the image and give it a glow:
[type=radio]:checked + img {
outline: 2px solid #f00;
border-radius: 32px;
overflow: hidden;
box-shadow: 0 0 5px 5px #f00;
}
I would use the following:
/ * CHECKED STYLES */
[type=radio]:checked + img {
border: 2px solid #f00;
border-radius: 50%
}
You should use borders for the rounded effect instead of outline. Set the border-radius for the image.
[type=radio]+img {
cursor: pointer;
height: 50px;
width: 50px;
}
[type=radio]:checked + img {
border: 2px solid #9ecaed;
border-radius: 50px;
box-shadow: 0 0 10px #9ecaed;
}
I would also recommend you to use javascript to toggle the radio button on click or you could just make the radio button the same size as your image. Of course the non-javascript way would be easier.
There are many ways to change the look of the native input element UI, use the below code to change the look of radio buttons.
.check_radio {
margin:15px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-direction: row;
flex-direction: row;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
cursor: pointer;
font-family: "Lato";
font-size: 14px;
color: #231E1E;
font-weight: 500;
line-height: 1.4;
}
.check_radio input[type="radio"] {
position: absolute;
opacity: 0;
}
.check_radio input[type="radio"] + span {
margin: 0 5px 0 0;
display: block;
height: 20px;
width: 20px;
background: #FFFFFF;
border: 1px solid #6E6B6B;
-webkit-box-sizing: border-box;
box-sizing: border-box;
border-radius: 50%;
-webkit-box-shadow: 0px 4px 8px rgb(44 39 56 / 8%);
box-shadow: 0px 4px 8px rgb(44 39 56 / 8%);
position: relative;
}
.check_radio input[type="radio"]:checked + span {
border: 2px solid #2474FF;
}
.check_radio input[type="radio"]:checked + span:after {
content: '';
background: #2474FF;
width: 10px;
height: 10px;
position: absolute;
border-radius: 50%;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
<label for="rm_1" class="check_radio">
<input type="radio" name="payment_type" id="rm_1">
<span></span>
Full Payment
</label>
<label for="rm_2" class="check_radio">
<input type="radio" name="payment_type" id="rm_2">
<span></span>
Partial Payment
</label>

Is the coding of the CSS incorrect? [duplicate]

This question already has an answer here:
How do I make :after box same size as parent and responsive? transform: scale(1) works, but why?
(1 answer)
Closed 2 years ago.
I have created a simple responsive login form. That allows the user to log-in and reset password. When filling out the username/password fields, both of these fields are mixed together and not on seperate lines. I have checked to see if the CSS layout was correct but I cannot seem to find a reason as to why the username and password fields do this.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: url(backgroundTwo.jpg) no-repeat center;
background-size: cover;
font-family: sans-serif;
}
.login {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
.form {
position: relative;
width: 100%;
max-width: 380px;
padding: 80px 40px 40px;
background: rgba(0, 0, 0, 0.7);
border-radius: 10px;
color: #fff;
box-shadow: 0 15px 25px rgba(0, 0, 0, 0.5);
}
.form::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 50%;
height: 100%;
background: rgba(255, 255, 255, 0.08);
border-radius: 10px;
pointer-events: none;
}
.form img {
position: absolute;
top: -50px;
left: calc(50% - 50px);
width: 100px;
background: rgba(255, 255, 255, 0.8);
border-radius: 50%;
}
.form h2 {
text-align: center;
letter-spacing: 1px;
margin-bottom: 2rem;
color: #ff652f;
}
.form .input input {
width: 100%;
padding: 10px 0;
font-size: 1rem;
letter-spacing: 1px;
margin-bottom: 30px;
border: none;
border-bottom: 1px solid #fff;
outline: none;
background-color: transparent;
color: indianred;
}
.form .input label {
position: absolute;
top: 0;
left: 0;
padding: 10px 0;
font-size: 1rem;
pointer-events: none;
transition: .3s ease-out;
}
.form .input input:focus+label .form .input input:valid+label {
transform: translateY(-18px);
color: #ff652f;
font-size: .8rem;
}
.submit-button {
display: block;
margin-left: auto;
border: none;
outline: none;
background: #ff652f;
font-size: 1rem;
text-transform: uppercase;
letter-spacing: 1px;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.forgot-password {
color: inherit;
}
#forgot-password {
position: absolute;
display: flex;
justify-content: center;
align-items: center;
top: 0;
left: 0;
right: 0;
height: 0;
z-index: #fff;
opacity: 0;
transition: 0.6s;
}
#forgot-password:target {
height: 100%;
opacity: 1;
}
.close {
position: absolute;
right: 1.5rem;
top: 0.5rem;
font-size: 2rem;
font-weight: 900;
text-decoration: none;
color: inherit;
}
<html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="LoginTwo.css">
<title>LoginFormTwo</title>
</head>
<body>
<div class="login">
<form action="" class="form">
<img src="avatarTwo.jpg" alt="">
<h2>Login</h2>
<div class="input">
<input type="text" name="loginUser" id="loginUser">
<label for="loginUser">User Name</label>
</div>
<div class="input">
<input type="password" name="loginPassword" id="loginPassword">
<label for="loginPassword">password</label>
</div>
<input type="submit" value="login" class="submit-button">
Forgot Password?
</form>
<div id="forgot-password">
<form action="" class="form">
×
<h2>Reset Password</h2>
<div class="input">
<input type="email" name="email" id="email" required>
<label for="email">Email</label>
</div>
<input type="submit" value="Submit" class="submit-button">
</form>
</div>
</div>
</body>
</html>
The problem I see here is that you didn't set a position: relative; to the <div> with class .input.
Since you set a position: absolute; to the label, its positioning is calculated from the closest parent with a position: relative; set. In your case, it's the <form> with class .form
Try adding these changes:
.form .input {
position: relative;
}
and adjust the top property of the label:
.form .input label {
top: -30px;
}
Here's a working Codepen
Hope this helps!
It's because your form is set to absolute so your labels are relative to the form.
By putting top: 0; your labels will be on top of the form. You can fix this by changing the .input position to relative like so:
.input {
position: relative;
}
And you can change the labels position by modifying the top value
.form .input label {
top: -25px /*or any value you want*/
}

how I could hover in the label upload and submit button in order to change the background and text

I use this code due to design upload and submit button does not use jquery or Javascript. I need to change upload and submit button background color and text color when hover it.
This is the code : JS Fiddle
* {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.inputBtnSection {
display: inline-block;
vertical-align: top;
font-size: 0;
font-family: verdana;
}
.disableInputField {
display: inline-block;
vertical-align: top;
height: 27px;
margin: 0;
font-size: 14px;
padding: 0 3px;
}
.fileUpload {
position: relative;
overflow: hidden;
border: solid 1px gray;
display: inline-block;
vertical-align: top;
}
.fileUpload2 {
position: relative;
overflow: hidden;
border: solid 1px gray;
display: inline-block;
vertical-align: top;
}
.uploadBtn {
display: inline-block;
vertical-align: top;
background: rgba(0, 0, 0, 0.5);
font-size: 14px;
padding: 0 10px;
height: 25px;
line-height: 22px;
color: #fff;
}
.uploadBtn2 {
display: inline-block;
vertical-align: top;
background: rgba(0, 0, 0, 0.5);
font-size: 14px;
padding: 0 10px;
height: 25px;
line-height: 22px;
color: #fff;
}
.fileUpload input.upload {
top: 0;
position: absolute;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
}
.fileUpload2 input.submit {
top: 0;
position: absolute;
right: 0;
margin: 0;
padding: 0;
font-size: 20px;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
}
<div class="formulir">
<form action="php/upload.php" method="post" enctype="multipart/form-data">
<div class="inputBtnSection">
<input id="uploadFile" class="disableInputField" placeholder="Choose File" disabled="disabled" />
<label class="fileUpload">
<input id="uploadBtn" type="file" class="upload" name="fileToUpload" />
<span class="uploadBtn">Browse File</span>
</label>
</div>
<label class="fileUpload2">
<input id="uploadtn2" type="submit" value="Upload Image" name="submit" class="submit">
<span class="uploadBtn2">upload</span>
</label>
</form>
</div>
Here is the Fiddle
Just added :hover class to the elements.
CSS:
.fileUpload:hover {
background-color: rgba(0, 0, 256, 0.5);
transition: all 0.25s;
}
.fileUpload2:hover {
background-color: green;
transition: all 0.25s;
}
You may try adding this to your css script:
.uploadBtn:hover{
display: inline-block;
vertical-align: top;
background: [the color on hover]
font-size: 14px;
padding: 0 10px;
height: 25px;
line-height: 22px;
color: #fff;
}
So I have only added :hover after the class name. Then do the same to the submit button.
Just add an :hover after your class. You only need to add the nessesary changes not everything.
.uploadBtn {
display:inline-block;
vertical-align:top;
background:rgba(0,0,0,0.5);
font-size:14px;
padding:0 10px;
height:25px;
line-height:22px;
color:#fff;}
.uploadBtn:hover {
background: [your new color];
color: [your new color];
}

Change CheckBox image to custom image

I have created a div with custom checkbox and i want to change the checkbox image by the custom image. and i have done it but i am unable to change the size of the image.Please help me.
Any help will be appreciated.
<div class="left">
<input id="Option" type="checkbox">
<label class="checkbox" for="Option"> </label>
</div>
And CSS which i have used.
.checkbox {
display: inline-block;
cursor: pointer;
font-size: 13px; line-height:18px;
}
input[type=checkbox] {
display:none;
}
.checkbox:before {
content: "";
display: inline-block;
width: 25px;
height: 25px;
vertical-align: middle;
background-color: rgb(248,183,51);
color: #f3f3f3;
text-align: center;
}
input[type=checkbox]:checked + .checkbox:before {
content: url("images/Tick.png");
text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
font-size: 15px;
}
You can do this without using images, just with simple characters and CSS, so you can make change on your custom checkbox just with adjusting font-size or changing color.
Please see the below example:
/* Base for label styling */
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
position: absolute;
left: -9999px;
}
[type="checkbox"]:not(:checked) + label,
[type="checkbox"]:checked + label {
position: relative;
padding-left: 25px;
cursor: pointer;
}
/* checkbox aspect */
[type="checkbox"]:not(:checked) + label:before,
[type="checkbox"]:checked + label:before {
content: '';
position: absolute;
left:0; top: 2px;
width: 17px; height: 17px;
border: 1px solid #aaa;
background: #f8f8f8;
border-radius: 3px;
box-shadow: inset 0 1px 3px rgba(0,0,0,.3)
}
/* checked mark aspect */
[type="checkbox"]:not(:checked) + label:after,
[type="checkbox"]:checked + label:after {
content: '✔';
position: absolute;
top: 3px; left: 4px;
font-size: 18px;
line-height: 0.8;
color: #09ad7e;
transition: all .1s;
transform-origin: center;
}
/* checked mark aspect changes */
[type="checkbox"]:not(:checked) + label:after {
opacity: 0;
transform: scale(0);
transform-origin: center;
}
[type="checkbox"]:checked + label:after {
opacity: 1;
transform: scale(1);
transform-origin: center;
}
/* disabled checkbox */
[type="checkbox"]:disabled:not(:checked) + label:before,
[type="checkbox"]:disabled:checked + label:before {
box-shadow: none;
border-color: #bbb;
background-color: #ddd;
}
[type="checkbox"]:disabled:checked + label:after {
color: #999;
}
[type="checkbox"]:disabled + label {
color: #aaa;
}
/* accessibility */
[type="checkbox"]:checked:focus + label:before,
[type="checkbox"]:not(:checked):focus + label:before {
border: 1px dotted blue;
}
/* hover style just for information */
label:hover:before {
border: 1px solid #4778d9!important;
}
/* Useless styles, just for demo design */
body {
font-family: "Open sans", "Segoe UI", "Segoe WP", Helvetica, Arial, sans-serif;
color: #777;
}
h1, h2 {
margin-bottom: 5px;
font-weight: normal;
text-align: center;
}
h2 {
margin: 5px 0 2em;
color: #aaa;
}
form {
width: 80px;
margin: 0 auto;
}
.txtcenter {
margin-top: 4em;
font-size: .9em;
text-align: center;
color: #aaa;
}
.copy {
margin-top: 2em;
}
.copy a {
text-decoration: none;
color: #4778d9;
}
<form action="#">
<p>
<input type="checkbox" id="test1" />
<label for="test1">Red</label>
</p>
<p>
<input type="checkbox" id="test2" checked="checked" />
<label for="test2">Yellow</label>
</p>
<p>
<input type="checkbox" id="test3" checked="checked" disabled="disabled" />
<label for="test3">Green</label>
</p>
<p>
<input type="checkbox" id="test4" disabled="disabled" />
<label for="test4">Brown</label>
</p>
</form>
or you can check on CodePen as well: Custom Checkbox Without images
(Edited)
Custom Checkbox background-image property
Please check the following live example for a custom checkbox using background-image:
.checkbox {
display: inline-block;
cursor: pointer;
font-size: 13px; line-height:18px;
}
input[type=checkbox] {
display:none;
}
.checkbox:before {
content: "";
display: inline-block;
width: 25px;
height: 25px;
vertical-align: middle;
background-color: rgb(248,183,51);
color: #f3f3f3;
text-align: center;
}
input[type=checkbox]:checked + .checkbox:before {
background: url("https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/checked_checkbox.png") no-repeat center center;
text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
font-size: 15px;
background-size: 10px 10px;
}
<div class="left">
<input id="Option" type="checkbox">
<label class="checkbox" for="Option"> </label>
</div>
Please make sure that your image is exist in right path.
Also please consider you can re-position your background image by setting the horizontal and vertical position for background property as well.
Main thing I did was set backgrounds background-size to cover.
.checkbox {
display: inline-block;
cursor: pointer;
font-size: 13px; line-height:18px;
}
input[type=checkbox] {
display:none;
}
.checkbox:before {
content: "";
display: inline-block;
width: 40px;
height: 40px;
vertical-align: middle;
background-color: rgb(248,183,51);
color: #f3f3f3;
text-align: center;
}
input[type=checkbox]:checked + .checkbox:before {
background: url("https://cdn1.iconfinder.com/data/icons/windows8_icons_iconpharm/26/checked_checkbox.png");
text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
font-size: 15px;
background-size: contain;
}
<div class="left">
<input id="Option" type="checkbox">
<label class="checkbox" for="Option"> </label>
</div>