Transform: Translate Imprecise In Firefox? - html

Codepen
I just created a custom selection pop-up. Now inspecting it in other browsers, I can't avoid, but notice the little offset of the white "dot", inside the radio button, Firefox renders. Chrome and Edge will display it just fine, but Firefow won't. And rather out of curiosity I'd like to know, why's that? And how to avoid?
The "dot":
&::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 50%;
height: 50%;
border-radius: 50%;
background-color: var(--light);
transform: translate(-50%, -50%);
}
Entire radio button:
input[type=radio] {
position: relative;
height: 24px;
width: 24px;
margin: 0;
border-radius: 50%;
border: solid 1px var(--light-contrast);
background-color: var(--light);
appearance: none;
cursor: pointer;
&:checked {
border-color: var(--accent);
background-color: var(--accent);
}
&:focus {
outline: 0;
}
&::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 50%;
height: 50%;
border-radius: 50%;
background-color: var(--light);
transform: translate(-50%, -50%);
}
}
Whole snippet:
:root {
--dark: #212121;
--dark-contrast: #424242;
--light: #fafafa;
--light-contrast: #cfd8dc;
--accent: #2196f3;
}
*,
::after,
::before {
box-sizing: border-box;
}
html {
font-family: 'Roboto', sans-serif;
font-size: 1rem;
line-height: 1.5;
}
body {
display: grid;
place-items: center;
height: 100vh;
margin: 0;
background-color: var(--dark);
}
ul, li {
margin: 0;
padding: 0;
list-style: none;
}
.select {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
max-width: 300px;
background-color: var(--dark-contrast);
color: #fff;
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.25);
cursor: pointer;
user-select: none;
padding: 1.25rem 1.5rem;
border-radius: 4px;
}
.select:focus {
outline: 0;
}
.select:focus .list {
opacity: 1;
transform: translate(-50%, -50%) scale(1);
pointer-events: all;
}
.select:hover {
background-color: #484848;
}
.select::after {
display: inline-block;
content: '';
border-left: .3755rem solid transparent;
border-right: .3755rem solid transparent;
border-top: .375rem solid #fff;
}
.select .list {
position: fixed;
top: 50%;
left: 50%;
width: clamp(300px, 75vw, 320px);
border-radius: 4px;
background-color: var(--light);
color: #000;
transform: translate(-50%, -50%) scale(0);
transition: all 400ms ease;
opacity: 0;
pointer-events: none;
overflow: hidden;
}
.select .list label {
display: flex;
align-items: center;
padding: 1.25rem 1.5rem;
cursor: pointer;
}
.select .list label:hover {
background-color: #ededed;
}
.select .list label:active {
background-color: #e1e1e1;
transition: 200ms ease;
}
.select .list label input[type=radio] {
margin-right: 1rem;
}
input[type=radio] {
position: relative;
height: 24px;
width: 24px;
margin: 0;
border-radius: 50%;
border: solid 1px var(--light-contrast);
background-color: var(--light);
appearance: none;
cursor: pointer;
}
input[type=radio]:checked {
border-color: var(--accent);
background-color: var(--accent);
}
input[type=radio]:focus {
outline: 0;
}
input[type=radio]::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 50%;
height: 50%;
border-radius: 50%;
background-color: var(--light);
transform: translate(-50%, -50%);
}
<div class="select" tabindex="1">
Select
<div class="list">
<label for="select-radio1">
<input type="radio" id="select-radio1" name="select-radio">
Chrome
</label>
<label for="select-radio2">
<input type="radio" id="select-radio2" name="select-radio">
Safari
</label>
<label for="select-radio3">
<input type="radio" id="select-radio3" name="select-radio">
Firefox
</label>
</div>
</div>

Subpixel rendering is handled differently across browsers.
As this SO-Post states:
[...] the problem arises from a different approach to subpixel calculus between browsers.
Also: there is no cross-browser solution, but only workarounds.

Related

How can I align a toggle button on the center of a div element?

I'm looking to place the toggle button aligned to the center of my element "Client_name" I created another div but I can't get the button to drop down and put it more to the right. Do you have any ideas?
The jsfiddle link is just below
https://jsfiddle.net/6cyuwxvf/
.switch {
position: relative;
display: inline-block;
width: 73px;
height: 32px;
}
.switch input {display:none;}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #CD3B1B;
-webkit-transition: .4s;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #89C445;
}
input:focus + .slider {
box-shadow: 0 0 1px #89C445;
}
input:checked + .slider:before {
-webkit-transform: translateX(86px);
-ms-transform: translateX(36px);
transform: translateX(38px);
}
.button10 {
background-color: white;
color: black;
border: 2px solid;
width: 500px;
height: 50px;
}
.div-permission {
display: table-cell;
vertical-align: middle;
height: 45px;
width: 900px;
border: 1px solid red;
}
You can use display: flex; with align-items: center; for vertical alignment and just add some margin to the switch.
.switch {
position: relative;
display: inline-block;
width: 73px;
height: 32px;
margin-left: 0.25rem;
}
.switch input {
display: none;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #CD3B1B;
-webkit-transition: .4s;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked+.slider {
background-color: #89C445;
}
input:focus+.slider {
box-shadow: 0 0 1px #89C445;
}
input:checked+.slider:before {
-webkit-transform: translateX(86px);
-ms-transform: translateX(36px);
transform: translateX(38px);
}
.button10 {
background-color: white;
color: black;
border: 2px solid;
width: 500px;
height: 50px;
}
.div-permission {
display: flex;
align-items: center;
height: 45px;
width: 900px;
border: 1px solid red;
}
<div class="div-permission">
<input type="text" class="button10" placeholder="Client_name" />
<label class="switch">
<input type="checkbox" id="togBtn" onclick="myFunction()" />
<div class="slider round"></div>
</label>
<input type="submit" id="myDIV" style="display: none;" name="valider" onclick="style.display = 'none'" />
</div>
In order to change the position, I use the CSS transform function.
Change your .switch class to this:
.switch {
position: relative;
display: inline-block;
width: 73px;
height: 32px;
top:50%;
left:10%;
transform: translate(-50%,-50%);
}
That should center it for you! All I added was the top, left, and transform functions in the class.

How to replace <b> </b> tags with a circle

I was told they should not be in there, but how do I remove them?
https://jsfiddle.net/jqzs6d3o/
That is all I am doing in the code.
Removing the <b> </b> tags from the html it.
How would that be done?
Is this something hard to do?
Removing <b></b> removes the blue circle. I want to keep the circle and remove <b></b>
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
.exitnew {
-webkit-appearance: none;
appearance: none;
position: relative;
box-sizing: border-box;
margin: auto;
padding: 0;
width: 48px;
height: 48px;
cursor: pointer;
background: transparent;
border: none;
border-radius: 50%;
clip-path: circle(50%);
transition: all 1s ease;
overflow: hidden;
}
.exitnew::before,
.exitnew::after {
content: "";
position: absolute;
height: 5px;
width: 38px;
top: 22px;
left: 5px;
right: 5px;
background: red;
transform: rotate(45deg);
transition: all 1s ease;
}
.exitnew::after {
transform: rotate(-45deg);
}
.exitnew:hover {
background: transparent;
}
.exitnew:hover::before,
.exitnew:hover::after {
background: green;
}
.exitnew b {
box-sizing: border-box;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border: 5px solid blue;
border-radius: 50%;
}
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
Added some styles #circle ID and changed your positioning a bit of .exitnew Also made b display: none; Check the changes below.
.exitnew {
-webkit-appearance: none;
appearance: none;
position: relative;
box-sizing: border-box;
margin: auto;
padding: 0;
width: 48px;
height: 48px;
cursor: pointer;
background: transparent;
border: none;
border-radius: 50%;
clip-path: circle(50%);
transition: all 1s ease;
overflow: hidden;
}
.exitnew::before,
.exitnew::after {
content: "";
position: absolute;
height: 5px;
width: 38px;
top: 17px;
left: -1px;
right: 5px;
background: red;
transform: rotate(45deg);
transition: all 1s ease;
}
.exitnew::after {
transform: rotate(-45deg);
}
.exitnew:hover {
background: transparent;
}
.exitnew:hover::before,
.exitnew:hover::after {
background: green;
}
.exitnew b {
display: none;
box-sizing: border-box;
position: relative;
width: 100%;
height: 100%;
border: 5px solid blue;
border-radius: 50%;
}
#circle {
background-color:#fff;
border-width: 2rem;
border:4px solid darkblue;
height:45px;
border-radius:50%;
-moz-border-radius:50%;
-webkit-border-radius:50%;
width: 45px;
margin-left: 1rem;
position: absolute;
}
<button class="exitnew" id="circle" type="button" aria-label="Close"><b></b></button>
You can utilize the button itself as the circle.
With this you’ll have cleaner code where you can just completely remove b tag without losing the circle.
.exitnew {
box-sizing: border-box;
position: absolute;
left: 0;
top: 0;
width: 38px;
height: 40px;
border: 5px solid blue;
border-radius: 50%;
}
Here’s the changes I made.
https://jsfiddle.net/Lnbuxvc0/

Creating a custom checkbox using CSS

I have the following code for creating custom checkboxes in CSS. Most of it is referenced from W3Schools and works pretty damn well.
.checkbox-container {
display: inline-block;
position: relative;
padding-left: 25px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
line-height: 16px;
}
.checkbox-container input {
/* Hide the default */
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkbox-container .checkmark {
position: absolute;
height: 16px;
width: 16px;
top: 0;
left: 0;
background-color: #ffffff;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 0.4rem;
}
.checkbox-container:hover input~.checkmark {
background-color: #ffffff;
border-color: rgba(0, 0, 0, 0.3);
}
.checkbox-container input:checked~.checkmark {
background-color: #1890ff;
border-color: #1890ff;
}
.checkbox-container .checkmark:after {
content: "";
position: absolute;
display: none;
}
.checkbox-container input:checked~.checkmark:after {
display: block;
}
.checkbox-container .checkmark:after {
left: 5px;
top: 1.5px;
width: 4px;
height: 8px;
border: solid #ffffff;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
<div>
<label class="checkbox-container">
Remember me
<input type="checkbox">
<span class="checkmark"></span>
</label>
</div>
Now the problem is, I want to change my markup. In fact I want to simplify it to something like this:
<div class="checkbox-container">
<input type="checkbox" name="remember-checkbox">
<label for="remember-checkbox">Remember me</label>
</div>
However, I can't seem to convert the CSS code to work with the new markup. I have tried converting the .checkmark to label:before, but that does not seem to work. Moreover, is it possible to show the check mark without having the <span> element? Thanks for any help.
You can update like below. Don't forget that for works with ID not name
.checkbox-container {
display: inline-block;
position: relative;
padding-left: 25px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
line-height: 16px;
}
.checkbox-container input {
/* Hide the default */
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
.checkbox-container label {
cursor:pointer;
}
.checkbox-container label:before {
content:"";
position: absolute;
height: 16px;
width: 16px;
top: 0;
left: 0;
background-color: #ffffff;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 0.4rem;
}
.checkbox-container:hover input~label:before {
background-color: #ffffff;
border-color: rgba(0, 0, 0, 0.3);
}
.checkbox-container input:checked~label:before {
background-color: #1890ff;
border-color: #1890ff;
}
.checkbox-container label:after{
content: "";
position: absolute;
display: none;
left: 6px;
top: 1.5px;
width: 4px;
height: 8px;
border: solid #ffffff;
border-width: 0 2px 2px 0;
transform: rotate(45deg);
}
.checkbox-container input:checked~label:after {
display: block;
}
<div class="checkbox-container">
<input type="checkbox" id="remember-checkbox">
<label for="remember-checkbox">Remember me</label>
</div>
Don't need to define id in checkbox input. You can also achieve by css only like checkbox input{ width:100%; height:100%; z-index:2; left:0; top:0 ...}.
You can follow below snippet.
.checkbox-container {
display: inline-block;
position: relative;
padding-left: 25px;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
line-height: 16px;
/*border: 1px solid red;*/
}
.checkbox-container input {
/* Hide the default */
position: absolute;
opacity: 0;
cursor: pointer;
height: 100%;
width: 100%;
left: 0;
top: 0;
z-index: 2;
}
.checkbox-container .checkmark{
position: relative;
cursor: pointer;
}
.checkbox-container .checkmark:before {
content: '';
position: absolute;
height: 16px;
width: 16px;
top: 0;
left: -25px;
background-color: #ffffff;
border: 1px solid rgba(0, 0, 0, 0.2);
border-radius: 0.25rem;
}
.checkbox-container:hover input~.checkmark:before {
background-color: #ffffff;
border-color: rgba(0, 0, 0, 0.3);
}
.checkbox-container input:checked~.checkmark:before {
background-color: #1890ff;
border-color: #1890ff;
}
.checkbox-container .checkmark:after{
content: "";
position: absolute;
left: -18.9px;
top: 1.9px;
width: 4px;
height: 8px;
border: solid #ffffff;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(90deg) scale(0);
-ms-transform: rotate(90deg) scale(0);
transform: rotate(90deg) scale(0);
transition: 350ms;
}
.checkbox-container input:checked~.checkmark:after {
opacity: 1;
-webkit-transform: rotate(45deg) scale(1);
-ms-transform: rotate(45deg) scale(1);
transform: rotate(45deg) scale(1);
}
<div class="checkbox-container">
<input type="checkbox" name="remember-checkbox">
<label class="checkmark">Remember me</label>
</div>

Overflow: hidden not being filled 100% by psuedo element?

It's hard to explain this. I'm trying to do something like this:
https://codepen.io/pen/yLBaJOq
.button {
position: relative;
display: inline-block;
padding: 20px;
line-height: 10px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
border: 9px solid black;
border-radius: 55px;
transition: all 0.35s ease-in-out;
color: black;
cursor: pointer;
overflow: hidden;
z-index: 1;
background-color: transparent;
}
.button:before {
content: '';
display: block;
position: absolute;
background-color: red;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-30deg);
transform-origin: center;
width: calc(100% + 30px);
height: 0;
padding-top: 0%;
transition: all 0.35s ease-in-out;
z-index: -1;
}
.button:hover {
color: #fff;
border: 9px solid red;
}
.button:hover:before {
padding-top: 200%;
}
But there's a thin line between the border and the element. Like the pseudo-element :before is not filling out the parent 100%. Image of what I mean:
It's happening in all browsers I'm trying (Chrome, FF, Safari, all Mac).
So I'm wondering if I can prevent this from happening, while still keeping a similar hover effect.
I could of course just use the transition on the background color and scrap the idea with the pseudo-element as the background.
Add background color to the button hover.
Change:
.button:hover {
color: #fff;
border: 9px solid red;
}
to:
.button:hover {
color: #fff;
border: 9px solid red;
background-color: red;
}
.button {
position: relative;
display: inline-block;
padding: 20px;
line-height: 10px;
font-size: 12px;
font-weight: bold;
text-transform: uppercase;
border: 9px solid black;
border-radius: 55px;
transition: all 0.35s ease-in-out;
color: black;
cursor: pointer;
overflow: hidden;
z-index: 1;
background-color: transparent;
}
.button:before {
content: '';
display: block;
position: absolute;
background-color: red;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) rotate(-30deg);
transform-origin: center;
width: calc(100% + 30px);
height: 0;
padding-top: 0%;
transition: all 0.35s ease-in-out;
z-index: -1;
}
.button:hover {
color: #fff;
border: 9px solid red;
background: red;
}
.button:hover:before {
padding-top: 200%;
}
<div class="button">WOAH</div>

Positioning the input form in the middle using margin: 0 auto not working

I'm trying to position the input form in the middle of form container using margin: 0 auto;, but not working.
I selected the div container and apply this:
.group {
position: relative;
top: 20px;
margin: 0 auto;
}
body {
background-color: Royalblue; /*#f0f0f0;*/
margin: 0px;
}
form {
position: relative;
top: 90px;
margin: 0 auto;
width: 280px;
height: 340px;
border: 1px solid #B0C4DE;
background: royalblue;
border-radius: 0px;
border-radius: 10px 10px 10px 10px;
}
/* Main EFFECT ================================ */
input {
position: relative;
top: 0px;
left: 0px;
font-family: 'Montserrat', sans-serif;
border: 0;
border-bottom: 1px solid white;
background: transparent;
font-size: 15px;
height: 25px;
width: 180px;
outline: 0;
z-index: 1;
color: black;
}
label {
display: block;
}
span {
position: absolute;
top: 7px;
left: 0px;
font-family: 'Montserrat', sans-serif;
font-size: 13px;
z-index: 1;
color: white;
transition: top .5s ease, font-size .5s ease;
}
.group {
position: relative;
top: 20px;
margin: 0 auto;
}
/*
label::after {
content: '';
position: absolute;
top: 5px;
left: 0px;
width: 200px;
height: 23px;
border-radius: 2px;
background: beige;
transition: transform .7s;
transform: scale3d(1, 0.1, 1);
transform-origin: bottom;
}
*/
/*
input:focus + label::after {
top: 5px;
transform: scale3d(1, 1.2, 1);
transition-timing-function: linear;
}
input:focus + label > span {
top: -20px;
font-size: 10px;
}
*/
<body>
<form>
<div class="group">
<input class="input1" type="email" id="email" required />
<label class="label1" for="email">
<span class="sp1">Email</span>
</label>
</div>
</form>
</body>
without width browser can not calculate how much margins it will put to left/right
you can see here in your case decrease width
http://prntscr.com/kvqscq
body {
background-color: Royalblue; /*#f0f0f0;*/
margin: 0px;
}
form {
position: relative;
top: 90px;
margin: 0 auto;
width: 280px;
height: 340px;
border: 1px solid #B0C4DE;
background: royalblue;
border-radius: 0px;
border-radius: 10px 10px 10px 10px;
}
/* Main EFFECT ================================ */
input {
position: relative;
top: 0px;
left: 0px;
font-family: 'Montserrat', sans-serif;
border: 0;
border-bottom: 1px solid white;
background: transparent;
font-size: 15px;
height: 25px;
width: 180px;
outline: 0;
z-index: 1;
color: black;
}
label {
display: block;
}
span {
position: absolute;
top: 7px;
left: 0px;
font-family: 'Montserrat', sans-serif;
font-size: 13px;
z-index: 1;
color: white;
transition: top .5s ease, font-size .5s ease;
}
.group {
position: relative;
top: 20px;
margin: 0 auto;
width: max-content;
}
/*
label::after {
content: '';
position: absolute;
top: 5px;
left: 0px;
width: 200px;
height: 23px;
border-radius: 2px;
background: beige;
transition: transform .7s;
transform: scale3d(1, 0.1, 1);
transform-origin: bottom;
}
*/
/*
input:focus + label::after {
top: 5px;
transform: scale3d(1, 1.2, 1);
transition-timing-function: linear;
}
input:focus + label > span {
top: -20px;
font-size: 10px;
}
*/
<body>
<form>
<div class="group">
<input class="input1" type="email" id="email" required />
<label class="label1" for="email">
<span class="sp1">Email</span>
</label>
</div>
</form>
</body>
Give your .group class below css, and you're all set...
.group {
width: max-content;
}
Now label will also move into center...
try this
.sp1{
left : 70px;
}