Is there a way make this html outline style different? - html

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>

Related

How to achieve exact radio button style design?

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>

checkbox styling and background

Is it possible to style check box like this, and change its background!
tried shadow box and the outline
the best I have reach is with the :before method but still not close
here what I have tried
CSS
.table__check-box {
background-color: red;
position: relative;
height: 1.75rem;
width: 1.75rem;
margin-right: 2.3rem;
margin-top: 1rem;
}
.table__check-box--inactive {
background-color: #a4a9ae;
}
.table__check-box:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
border-radius: 5px;
border: 2px solid #ccc;
}
HTML
<input class="table__check-box" type="checkbox">
Input element does not have content, so there should be no :before. Better use table__check-box + label:before:
* {
box-sizing: border-box;
}
.table__check-box {
opacity: .3;// Just for display
// Uncomment:
// display: none;
}
.table__check-box + label {
background-color: red;
display: inline-block;
position: relative;
height: 1.75rem;
width: 1.75rem;
margin-right: 2.3rem;
margin-top: 1rem;
overflow: hidden;
border-radius: 5px;
border: 2px solid #ccc;
}
.table__check-box:not(:checked) + label {
background-color: #a4a9ae;
}
<div class="input-wrapper">
<input id="active-checkbox" class="table__check-box" type="checkbox"/>
<label for="active-checkbox"></label>
</div>
w3schools has a good post on this.
Tweaking their example slightly, you'll want to wrap your checkbox in a label, form elements should always have labels and it gives you the option to add an optional text label (like in the fiddle).
<label class="checkbox-container">
<input type="checkbox" checked="checked">
<span class="checkbox-state"></span>
</label>
<label class="checkbox-container">
<input type="checkbox">
<span class="checkbox-state"></span>
</label>
<label class="checkbox-container">
<input type="checkbox">
<span class="checkbox-state"></span>
</label>
/* Customize the label (the container) */
.checkbox-container {
display: block;
position: relative;
margin: 10px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default checkbox */
.checkbox-container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Style the checkbox */
.checkbox-container input ~ .checkbox-state {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 5px;
display: block;
width: 20px;
height: 20px;
}
/* Style the checkbox */
.checkbox-container input:checked ~ .checkbox-state {
background-color: #ccc;
}
Working fiddle: https://jsfiddle.net/zano29jd/

Position off for absolutely positioned input in Safari

I have this very strange issue in Safari, both desktop and iOS. Here is a screenshot of what is currently happening (again, both iOS and desktop Safari):
And here is a picture of what should be happening (taken from Chrome on Mac, but also confirmed the same in Android Chrome and Firefox):
Here is the HTML:
<label class="radio-selections" for="maleSelection">Male
<input type="radio" value="male" id="maleSelection" name="gender">
</label>
And here is the CSS:
label.radio-selections {
width: 95%;
max-width: 400px;
height: 55px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
color: var(--dark-gray);
transition: box-shadow 100ms;
border-radius: 6px;
input[type=radio] {
apperance: none;
-webkit-appearance: none;
height: inherit;
width: inherit;
max-width: inherit;
position: absolute;
border-radius: 6px;
z-index: -1;
background-color: transparent;
cursor: pointer;
}
&[for=femaleSelection] {
box-shadow: 0 1px 7px 3px rgba(147,64,169,.65);
&:active {
box-shadow: 0 1px 7px 1px rgba(147,64,169,.35);
}
input[type=radio]:checked {
background-color: rgba(147,64,169,.15)
}
}
&[for=maleSelection] {
box-shadow: 0 1px 7px 3px rgba(64,93,169,.65);
&:active {
box-shadow: 0 1px 7px 1px rgba(64,93,169,.35);
}
input[type=radio]:checked {
background-color: rgba(64,93,169,.15)
}
}
}
I think it could be well understood what I'm lacking here, but why is the "checked" styling in iOS and Safari offset, while in all other browsers it is overlapping as it should?
Here is also a pretty simple codepen that pretty much outlines what I'm looking for (obviously works in Chrome, but not in Safari):
https://codepen.io/adammcgurk/pen/wvvJWry
Use position: relative; on parent when ever you make any element absolute so that it adjust itself according to its parent.
label.radio-selections {
position: relative;
}
and then on child make left right top and bottom to 0
input[type=radio] {
left: 0;
right: 0;
bottom: 0;
top: 0;
}

How to design non fill rounded checkbox using pure css

I am making a styled rounded checkbox for woocommerce . The Problem is my checkbox is now fill inside . How Can I make it thin inside without filling?
input#createaccount:checked {
background-color: #253849;
}
input#createaccount{
position: relative;
margin-left: 4px;
width: 25px;
float: left;
margin: 2px 10px 2px 1px;
height: 25px;
border-radius: 50%;
vertical-align: middle;
border: 4px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
}
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">
One way to do this without javascript would be to create one wrapper element with input and one more element as a indicator for checkbox state. That way you can use selector input:checked + nextElement and change style of second element based on checkbox status.
Then you just have to hide checkbox with opacity: 0. With this approach you can also use transitions and transforms on the inner element.
.checkbox-el {
position: relative;
margin-left: 4px;
width: 25px;
float: left;
margin: 2px 10px 2px 1px;
height: 25px;
border-radius: 50%;
vertical-align: middle;
border: 2px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
padding: 5px;
}
.checkbox-el input {
width: 100%;
height: 100%;
position: absolute;
top: -3px;
left: -3px;
z-index: 5;
opacity: 0;
cursor: pointer;
}
.checkbox-circle {
position: relative;
border-radius: 50%;
width: 100%;
height: 100%;
z-index: 1;
transform: scale(0.5);
transition: all 0.25s ease-in;
}
.checkbox-el input:checked + .checkbox-circle {
background-color: #253849;
transform: scale(1)
}
<span class="checkbox-el">
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">
<div class="checkbox-circle"></div>
</span>
Simple adding inner shadow solve the issue
box-shadow: inset 0px 0px 0px 5px #ffffff;
input#createaccount:checked {
background-color: #253849;
box-shadow: inset 0px 0px 0px 5px #ffffff;
transition: 0.5s;
}
input#createaccount{
position: relative;
margin-left: 4px;
width: calc(3em - 4px);
height: calc(3em - 4px);
float: left;
margin: 4px 10px 2px 1px;
border-radius: 50%;
vertical-align: middle;
border: 5px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
transition: 0.5s;
}
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">
Here is another trick with a simple background where you color the content-box and you animate the padding. You will also have transparency:
input#createaccount:checked {
padding:3px;
}
input#createaccount {
width: 25px;
float: left;
margin: 2px 10px 2px 1px;
height: 25px;
border-radius: 50%;
vertical-align: middle;
border: 4px solid #295282;
-webkit-appearance: none;
outline: none;
cursor: pointer;
box-sizing:border-box;
background: #253849 content-box;
padding:8.5px; /* 25/2 - 4 */
transition:0.3s all;
}
body {
background:pink;
}
<input class="input-checkbox" id="createaccount" type="checkbox" name="createaccount" value="1">

How to make checkboxes rounded?

Is there any way to make checkboxes with rounded corners using bootstrap or some css property?
Just using css, however, you lose the checkbox tick.
.checkbox-round {
width: 1.3em;
height: 1.3em;
background-color: white;
border-radius: 50%;
vertical-align: middle;
border: 1px solid #ddd;
appearance: none;
-webkit-appearance: none;
outline: none;
cursor: pointer;
}
.checkbox-round:checked {
background-color: gray;
}
<input type="checkbox" class="checkbox-round" />
.container {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default checkbox */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
border-radius: 15px;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.container .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
<label class="container">One
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">Two
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Three
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Four
<input type="checkbox">
<span class="checkmark"></span>
</label>
Try to do
body {
background-color: #f1f2f3;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
}
.container {
margin: 0 auto;
}
.round {
position: relative;
}
.round label {
background-color: #fff;
border: 1px solid #ccc;
border-radius: 50%;
cursor: pointer;
height: 28px;
left: 0;
position: absolute;
top: 0;
width: 28px;
}
.round label:after {
border: 2px solid #fff;
border-top: none;
border-right: none;
content: "";
height: 6px;
left: 7px;
opacity: 0;
position: absolute;
top: 8px;
transform: rotate(-45deg);
width: 12px;
}
.round input[type="checkbox"] {
visibility: hidden;
}
.round input[type="checkbox"]:checked + label {
background-color: #66bb6a;
border-color: #66bb6a;
}
.round input[type="checkbox"]:checked + label:after {
opacity: 1;
}
<div class="container">
<div class="round">
<input type="checkbox" id="checkbox" />
<label for="checkbox"></label>
</div>
</div>
One of the Best And Easiest Method is to use CSS clip path property:
<input type="checkbox" id="checkbox" />
<label for="checkbox" >Option</label>
input[type="checkbox"] {
width: 45px; /* Set width */
height: 45px; /* Set height */
clip-path: circle(46% at 50% 50%); /* Set the clip path of circle*/
}
if you still see some pointed corners, try reducing the first percentage values, (where I have used 46%), play with it a little bit and it will definitely work.
Well, this is the simplest and optimal solution. You set appearance to none and then use clip-path when its checked.
.rounded-checkbox {
width:35px;
height: 35px;
border-radius: 50%;
vertical-align: middle;
border: 1px solid black;
appearance: none;
-webkit-appearance: none;
outline: none;
cursor: pointer;
}
.rounded-checkbox:checked {
appearance: auto;
clip-path: circle(50% at 50% 50%);
background-color: blue;
}
<input
type="checkbox"
class="rounded-checkbox"
id="checkbox"
/> <label for="checkbox">Checkbox</label>
in css you may play with height, width, border-radius. basically height and width should be equal and border-radius should be half of them.
if you are using bootstrap you can use this class and add it where your shape or in this case your checkbox class is: class="rounded-circle"
look: borders bootstrap 5
for example to make a checkbox rounded in bootstrap 5 (also working for v4):
<div class="form-check">
<input
class="form-check-input rounded-circle"
type="checkbox"
/>
<label class="form-check-label" for="flexCheck1">
rounded checkbox
</label>
</div>
CSS
.checkbox {
clip-path: circle(46% at 50% 50%);
}
HTML
<input type="checkbox" class="checkbox" />
No need to hide the default checkbox and create a custom just set the clip-path and you can easily achieve a circular checkbox.
I thing the best way to make a rounded corners is by using the border-radius property. This site has a nice collection of checkboxes.
For example:
cursor: pointer;
position: absolute;
width: 20px;
height: 20px;
top: 0;
border-radius: 10px;
The last line(border-radius: 10px) will give you a checkbox with rounded corners.