I am trying to figure it out but don't know to how to convert this SCSS file into Css file can you please help me to solve this problem any help would be appreciated i want this animation hover effect but in simple I tried to add this scss but its not working properly some
Here its codepen link : https://codepen.io/electerious/pen/qPjbGm
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #fcf3ec;
}
.button {
--offset: 10px;
--border-size: 2px;
display: block;
position: relative;
padding: 1.5em 3em;
appearance: none;
border: 0;
background: transparent;
color: #e55743;
text-transform: uppercase;
letter-spacing: .25em;
outline: none;
cursor: pointer;
font-weight: bold;
border-radius: 0;
box-shadow: inset 0 0 0 var(--border-size) currentcolor;
transition: background .8s ease;
&:hover {
background: rgba(100, 0, 0, .03);
}
&__horizontal,
&__vertical {
position: absolute;
top: var(--horizontal-offset, 0);
right: var(--vertical-offset, 0);
bottom: var(--horizontal-offset, 0);
left: var(--vertical-offset, 0);
transition: transform .8s ease;
will-change: transform;
&::before {
content: '';
position: absolute;
border: inherit;
}
}
&__horizontal {
--vertical-offset: calc(var(--offset) * -1);
border-top: var(--border-size) solid currentcolor;
border-bottom: var(--border-size) solid currentcolor;
&::before {
top: calc(var(--vertical-offset) - var(--border-size));
bottom: calc(var(--vertical-offset) - var(--border-size));
left: calc(var(--vertical-offset) * -1);
right: calc(var(--vertical-offset) * -1);
}
}
&:hover &__horizontal {
transform: scaleX(0);
}
&__vertical {
--horizontal-offset: calc(var(--offset) * -1);
border-left: var(--border-size) solid currentcolor;
border-right: var(--border-size) solid currentcolor;
&::before {
top: calc(var(--horizontal-offset) * -1);
bottom: calc(var(--horizontal-offset) * -1);
left: calc(var(--horizontal-offset) - var(--border-size));
right: calc(var(--horizontal-offset) - var(--border-size));
}
}
&:hover &__vertical {
transform: scaleY(0);
}
}
<button class="button">
Fancy Button
<div class="button__horizontal"></div>
<div class="button__vertical"></div>
</button>
In this Codepen CSS code block there is a dropdown click on it and then choose view compiled CSS it will convert SCSS to CSS.
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #fcf3ec;
}
.button {
--offset: 10px;
--border-size: 2px;
display: block;
position: relative;
padding: 1.5em 3em;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: 0;
background: transparent;
color: #e55743;
text-transform: uppercase;
letter-spacing: 0.25em;
outline: none;
cursor: pointer;
font-weight: bold;
border-radius: 0;
box-shadow: inset 0 0 0 var(--border-size) currentcolor;
transition: background 0.8s ease;
}
.button:hover {
background: rgba(100, 0, 0, 0.03);
}
.button__horizontal, .button__vertical {
position: absolute;
top: var(--horizontal-offset, 0);
right: var(--vertical-offset, 0);
bottom: var(--horizontal-offset, 0);
left: var(--vertical-offset, 0);
transition: transform 0.8s ease;
will-change: transform;
}
.button__horizontal::before, .button__vertical::before {
content: "";
position: absolute;
border: inherit;
}
.button__horizontal {
--vertical-offset: calc(var(--offset) * -1);
border-top: var(--border-size) solid currentcolor;
border-bottom: var(--border-size) solid currentcolor;
}
.button__horizontal::before {
top: calc(var(--vertical-offset) - var(--border-size));
bottom: calc(var(--vertical-offset) - var(--border-size));
left: calc(var(--vertical-offset) * -1);
right: calc(var(--vertical-offset) * -1);
}
.button:hover .button__horizontal {
transform: scaleX(0);
}
.button__vertical {
--horizontal-offset: calc(var(--offset) * -1);
border-left: var(--border-size) solid currentcolor;
border-right: var(--border-size) solid currentcolor;
}
.button__vertical::before {
top: calc(var(--horizontal-offset) * -1);
bottom: calc(var(--horizontal-offset) * -1);
left: calc(var(--horizontal-offset) - var(--border-size));
right: calc(var(--horizontal-offset) - var(--border-size));
}
.button:hover .button__vertical {
transform: scaleY(0);
}
Related
I need to turn around the hover effect of an element. Right now, the border disappears when you hover over it, but I want it to be hidden by default and only appears when you hover over it?
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #fcf3ec;
}
.button {
--offset: 10px;
--border-size: 2px;
display: block;
position: relative;
padding: 1.5em 3em;
appearance: none;
border: 0;
background: transparent;
color: #e55743;
text-transform: uppercase;
letter-spacing: .25em;
outline: none;
cursor: pointer;
font-weight: bold;
border-radius: 0;
box-shadow: inset 0 0 0 var(--border-size) currentcolor;
transition: background .8s ease;
}
.button:hover {
background: rgba(100, 0, 0, .03);
}
.button__horizontal,
.button__vertical {
position: absolute;
top: var(--horizontal-offset, 0);
right: var(--vertical-offset, 0);
bottom: var(--horizontal-offset, 0);
left: var(--vertical-offset, 0);
transition: transform .8s ease;
will-change: transform;
}
.button__horizontal::before .button__vertical::before {
content: '';
position: absolute;
border: inherit;
}
.button__horizontal {
--vertical-offset: calc(var(--offset) * -1);
border-top: var(--border-size) solid currentcolor;
border-bottom: var(--border-size) solid currentcolor;
}
.button__horizontal::before {
top: calc(var(--vertical-offset) - var(--border-size));
bottom: calc(var(--vertical-offset) - var(--border-size));
left: calc(var(--vertical-offset) * -1);
right: calc(var(--vertical-offset) * -1);
}
.button:hover .button__horizontal {
transform: scaleX(0);
}
.button__vertical {
--horizontal-offset: calc(var(--offset) * -1);
border-left: var(--border-size) solid currentcolor;
border-right: var(--border-size) solid currentcolor;
}
.button__vertical::before {
top: calc(var(--horizontal-offset) * -1);
bottom: calc(var(--horizontal-offset) * -1);
left: calc(var(--horizontal-offset) - var(--border-size));
right: calc(var(--horizontal-offset) - var(--border-size));
}
.button:hover .button__vertical {
transform: scaleY(0);
}
<button class="button">
Fancy Button
<div class="button__horizontal"></div>
<div class="button__vertical"></div>
</button>
Here you can see how the effect works and also the original code:
https://codepen.io/electerious/details/qPjbGm
How can I make this effect the other way round?
All you need to do is change where you use the transform.
.button__vertical {
transform: scaleY(0);
--horizontal-offset: calc(var(--offset) * -1);
border-left: var(--border-size) solid currentcolor;
border-right: var(--border-size) solid currentcolor;
}
.button:hover .button__vertical {
transform: scaleY(1);
}
With that its not visible and once you hover you scale it. you will obvs need to do the same for the button__horizontal class but for the scaleX
Here is an easier idea with less of code and only the button tag:
.button {
--offset: 10px;
--border-size: 2px;
padding: 1.5em 3em;
border: var(--offset) solid transparent;
appearance: none;
color: #e55743;
text-transform: uppercase;
letter-spacing: .25em;
cursor: pointer;
font-weight: bold;
--_g: currentColor var(--border-size),#0000 0 calc(100% - var(--border-size)),currentColor 0;
background:
linear-gradient(90deg,var(--_g)) 50%/calc(100% - 2*var(--offset)) 100% border-box,
linear-gradient( var(--_g)) 50%/100% calc(100% - 2*var(--offset)) border-box,
padding-box;
background-repeat: no-repeat;
clip-path: inset(var(--offset));
transition: .8s ease;
}
.button:hover {
background-color: rgba(100, 0, 0, .03);
clip-path: inset(0);
}
body {
display: grid;
place-content: center;
height: 100vh;
margin: 0;
background: #fcf3ec;
}
<button class="button">Fancy Button</button>
I need to display a tooltip when hover an option of dropdown. The dropdown used here is react-windowed-select, which a wrapper of react-select. For some reasons, I end up create my own tooltip using css only (not invented by me though, found somewhere from internet). It work great, except, the tooltip is cropped (not fully displayed) for the first data of the options. Here is the screenshot of what I've done:
My objective, how to make this tooltip appear above everything?
Here is the code I'm working so far: https://codesandbox.io/s/friendly-wu-wlitr?file=/src/App.tsx
in case the link of the code broken, here is the code for the corresponding file:
CustomTooltip.tsx
import React from "react";
import "./CustomTooltip.css";
interface CustomTooltipProps {
dataTip: string;
children: React.ReactNode;
position?: "top" | "right" | "left" | "bottom";
}
export default function CustomTooltip({
children,
dataTip,
position = "top"
}: CustomTooltipProps) {
return (
<div className="tooltip-css">
<div
className={`qtip tip-${position}`}
data-tip={dataTip}
style={{ width: "100%" }}
>
{children}
</div>
</div>
);
}
Here is the styling, CustomTooltip.css
/*tipped element. should be inline-block or block*/
/**
source: https://speckyboy.com/free-css-tooltip-snippets/
*/
.tooltip-css {
/*the tip*/
/*top*/
/*bottom*/
/*left*/
/*right*/
/*some styles for this example*/
width: 100%;
}
.tooltip-css .qtip {
display: inline-block;
position: relative;
box-sizing: border-box;
font-style: default;
transition: all 0.7s ease-in-out;
overflow: visible;
}
.tooltip-css .qtip:hover {
cursor: default;
}
.tooltip-css .qtip:before {
content: attr(data-tip);
font-size: 14px;
position: absolute;
background: rgba(10, 20, 30, 0.85);
color: #fff;
line-height: 1.2em;
padding: 1em;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
min-width: 120px;
max-width: 400px;
width: fit-content;
text-align: center;
opacity: 0;
visibility: hidden;
transition: all 0.7s ease-in-out;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
letter-spacing: 0;
}
.tooltip-css .qtip:after {
width: 0;
height: 0;
border-style: solid;
content: "";
position: absolute;
opacity: 0;
visibility: hidden;
transition: all 0.7s ease-in-out;
}
.tooltip-css .qtip:hover:before,
.tooltip-css .qtip:hover:after {
visibility: visible;
opacity: 1;
overflow: visible;
}
.tooltip-css .qtip.tip-top:before {
top: 0;
left: 50%;
transform: translate(-50%, calc(-100% - 8px));
box-sizing: border-box;
border-radius: 3px;
}
.tooltip-css .qtip.tip-top:after {
border-width: 8px 8px 0 8px;
border-color: rgba(10, 20, 30, 0.85) transparent transparent transparent;
top: -8px;
left: 50%;
transform: translate(-50%, 0);
}
.tooltip-css .qtip.tip-bottom:before {
bottom: 0;
left: 50%;
transform: translate(-50%, calc(100% + 8px));
box-sizing: border-box;
border-radius: 3px;
}
.tooltip-css .qtip.tip-bottom:after {
border-width: 0 8px 8px 8px;
border-color: transparent transparent rgba(10, 20, 30, 0.85) transparent;
bottom: -8px;
left: 50%;
transform: translate(-50%, 0);
}
.tooltip-css .qtip.tip-left:before {
left: 0;
top: 50%;
transform: translate(calc(-100% - 8px), -50%);
box-sizing: border-box;
border-radius: 3px;
}
.tooltip-css .qtip.tip-left:after {
border-width: 8px 0 8px 8px;
border-color: transparent transparent transparent rgba(10, 20, 30, 0.85);
left: -8px;
top: 50%;
transform: translate(0, -50%);
}
.tooltip-css .qtip.tip-right:before {
right: 0;
top: 50%;
transform: translate(calc(100% + 8px), -50%);
box-sizing: border-box;
border-radius: 3px;
}
.tooltip-css .qtip.tip-right:after {
border-width: 8px 8px 8px 0;
border-color: transparent rgba(10, 20, 30, 0.85) transparent transparent;
right: -8px;
top: 50%;
transform: translate(0, -50%);
}
.tooltip-css body {
background: #3bb4e5;
}
.tooltip-css .container {
padding: 1.5em;
margin: 3em auto;
background: #fff;
position: relative;
max-width: 720px;
font-size: calc(2vmin + 12px);
line-height: 1.5em;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.3);
font-weight: 500;
text-align: center;
}
.tooltip-css .container p {
margin: 0 auto 0.8em;
}
.tooltip-css .container h1 {
text-align: center;
line-height: 1em;
color: #d40;
margin: 0 auto 0.5em;
font-size: 2.5em;
}
.tooltip-css code {
color: #3bb4e5;
font-size: 0.8em;
padding: 1em;
background: #0a141e;
display: block;
text-align: left;
}
.tooltip-css .hl {
color: #eb1777;
}
.tooltip-css .qcontent {
color: #ff0;
font-weight: bold;
}
.tooltip-css .qclass {
color: #dd0;
font-weight: bold;
}
And here how I combine all of them, App.tsx
import "./styles.css";
import Select, { components } from "react-select";
import { CustomTooltip } from "./custom-tooltip";
const data = Array.from(Array(100)).map((item, index) => {
return {
value: index + 1,
label: `data ${index + 1}`
};
});
export default function App() {
return (
<div
style={{
width: "80%"
}}
>
<h1>Data</h1>
<Select
options={data}
components={{
Option: (props) => {
return (
<components.Option {...props}>
<CustomTooltip dataTip={`${props.data.label}`}>
<div>{`${props.data.value}`}</div>
</CustomTooltip>
</components.Option>
);
}
}}
/>
</div>
);
}
How do I create a switch toggle input where a "Y" and "N" appears 'above' the input?
In the snippet below, I have a problem where the z-index of the "Y" and "N" covers the input so it is only toggle-able if you click around the z-indexed spans.
Additionally, I would like the letters to change color when the checkbox is toggled, but that is a secondary issue, I think.
body, html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
.switch__input {
position: absolute;
top: 0;
left: 0;
width: 90px;
height: 50px;
opacity: 0;
z-index: 0;
}
.switch__label:before {
content: '';
text-align: center;
position: absolute;
color: red;
top: 5px;
left: 0;
width: 90px;
height: 35px;
background-color: rgba(0, 0, 0, 0.26);
border-radius: 100px;
z-index: 0;
-webkit-transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.switch__label:after {
content: '';
color: white;
position: absolute;
text-align: center;
font-size: 24px;
padding: 4.4px 0;
top: -2px;
left: 0;
width: 50px;
height: 50px;
background-color: #2d95e5;
border-radius: 100px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
z-index: 0;
-webkit-transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
-webkit-transition-property: left, background-color;
transition-property: left, background-color;
}
.switch__input:checked + .switch__label:before {
background-color: rgba(225, 225, 225, 0.5);
}
.switch__input:checked + .switch__label:after {
left: 40px;
content: '';
color: white;
background-color: #BFBFBF;
}
.yesnocontainer {
font-family: sans-serif;
display: flex;
width: 70px;
justify-content: space-evenly;
align-content: center;
}
.yes, .no {
font-size: 24px;
}
.yes {
position: relative;
color: black !important;
z-index: 999 !important;
}
.no {
position: relative;
color: black !important;
z-index: 999 !important;
}
<div class="switch">
<input type="checkbox" id="switch1" class="switch__input" checked>
<label for="switch1" class="switch__label"></label>
<span class="yesnocontainer">
<span class="yes">Y</span>
<span class="no">N</span>
</span>
</div>
.switch-toggle {
float: left;
background: gray;
}
.switch-toggle input {
position: absolute;
opacity: 0;
}
.switch-toggle input + label {
padding: 7px;
float:left;
color: #fff;
cursor: pointer;
}
.switch-toggle input:checked + .red {
background: red;
}
.switch-toggle input:checked + .green {
background: green;
}
<div class="switch-toggle switch-3 switch-candy">
<input id="on" name="state-d" class="green" type="radio" />
<label for="on" class="green" onclick="">ON</label>
<input id="off" name="state-d" class="red" type="radio" />
<label for="off" class="red" onclick="">OFF</label>
</div>
.switch__label must be visibled on screen, try this.
body, html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
/* ADD .switch__label */
.switch__input,.switch__label {
position: absolute;
top: 0;
left: 0;
width: 90px;
height: 50px;
opacity: 0;
z-index: 0;
}
/*ADD*/
.switch__label{
z-index:2;
opacity:1;
}
.switch__label:before {
content: '';
text-align: center;
position: absolute;
color: red;
top: 5px;
left: 0;
width: 90px;
height: 35px;
background-color: rgba(0, 0, 0, 0.26);
border-radius: 100px;
z-index: 0;
-webkit-transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition: background-color 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.switch__label:after {
content: '';
color: white;
position: absolute;
text-align: center;
font-size: 24px;
padding: 4.4px 0;
top: -2px;
left: 0;
width: 50px;
height: 50px;
background-color: #2d95e5;
border-radius: 100px;
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
z-index: 0;
-webkit-transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
transition: all 0.28s cubic-bezier(0.4, 0, 0.2, 1);
-webkit-transition-property: left, background-color;
transition-property: left, background-color;
}
.switch__input:checked + .switch__label:before {
background-color: rgba(225, 225, 225, 0.5);
}
.switch__input:checked + .switch__label:after {
left: 40px;
content: '';
color: white;
background-color: #BFBFBF;
}
.yesnocontainer {
font-family: sans-serif;
display: flex;
width: 70px;
justify-content: space-evenly;
align-content: center;
}
.yes, .no {
font-size: 24px;
}
.yes {
position: relative;
color: black !important;
z-index: 1;
}
/* ADD */
.switch__input:checked + .switch__label + .yesnocontainer > .no {
z-index:3;
}
.no {
position: relative;
color: black !important;
z-index: 1;
}
/* ADD */
.switch__input:not(:checked) + .switch__label + .yesnocontainer > .yes {
z-index:3;
}
<div class="switch">
<input type="checkbox" id="switch1" class="switch__input" checked>
<label for="switch1" class="switch__label"></label>
<span class="yesnocontainer">
<span class="yes">Y</span>
<span class="no">N</span>
</span>
</div>
.btn-text {
background: transparent;
box-sizing: border-box;
text-decoration: none;
box-shadow: inset 0 0 0 1px transparent;
border-bottom: 1px solid transparent;
color: red;
padding: 8px 12px 0;
font-size: inherit;
font-weight: 500;
position: relative;
width:100px;
display:block;
vertical-align: middle;
animation: before 0.4s ease;
transition: all 0.4s ease;
margin-top: 30px;
}
.btn-text::before, .btn-text::after {
box-sizing: inherit;
content: "";
position: absolute;
width: 100%;
height: 100%;
}
.btn-text:active {
transform: translateY(0);
box-shadow: 0 1rem 0.5rem rgba(0, 0, 0, 0.2);
}
.btn-text:hover {
text-decoration: none;
color: red;
border-bottom: 1px solid transparent;
}
.btn-text::before, .btn-text::after {
top: 0;
left: 0;
height: 100%;
width: 100%;
transform-origin: center;
}
.btn-text::before {
border-top: 1px solid red;
border-bottom: 1px solid red;
transform: scale3d(0, 1, 1);
}
.btn-text::after {
border-left: 1px solid red;
border-right: 1px solid red;
transform: scale3d(1, 0, 1);
}
.btn-text:hover::before, .btn-text:hover::after {
animation: border 0.5s ease forwards;
}
.btn-text span {
display: block;
border-bottom: 1px solid red;
margin-top: 8px;
}
#keyframes border {
to{
transform: scale3d(1,1,1);
}
}
<a href="#!" class="btn-text " style="width: fit-content">know
more
<span></span>
</a>
I am trying to add a cool hover in animation effect. When I hover over the button I am calling an animation which scaling up borders .
My problem is that when I hover out of button it goes back to the initial state without animation.
I want that the same animation should reverse when I hover out.
You don't need an animation for this, you need a transition...like so:
Codepen Demo
* {
box-sizing: border-box;
}
.btn-text {
background: transparent;
text-decoration: none;
box-shadow: inset 0 0 0 1px transparent;
border-bottom: 1px solid transparent;
color: red;
padding: 8px 12px 0;
font-size: inherit;
font-weight: 500;
position: relative;
width: 100px;
display: block;
vertical-align: middle;
margin-top: 30px;
margin-left: 30px;
}
.btn-text::before,
.btn-text::after {
box-sizing: inherit;
content: "";
position: absolute;
width: 100%;
height: 100%;
transition: transform .5s;
}
.btn-text:hover {
text-decoration: none;
color: red;
border-bottom: 1px solid transparent;
}
.btn-text::before,
.btn-text::after {
top: 0;
left: 0;
height: 100%;
width: 100%;
transform-origin: center;
}
.btn-text::before {
border-top: 1px solid red;
border-bottom: 1px solid red;
transform: scale3d(0, 1, 1);
}
.btn-text::after {
border-left: 1px solid red;
border-right: 1px solid red;
transform: scale3d(1, 0, 1);
}
.btn-text:hover::before {
transform: scale3d(1, 1, 1);
}
.btn-text:hover::after {
transform: scale3d(1, 1, 1);
}
.btn-text span {
display: block;
border-bottom: 1px solid red;
margin-top: 8px;
}
<a href="#!" class="btn-text " style="width: fit-content">know more
<span></span>
</a>
I have made this button by editing "Simple Hover Effect by Vincent Durand". But the problem is that some css in my blog is overlapping. So it is not aligning to middle correctly. I cant find which one it may be. I tried using !important tag in some places. But I guess it didn't work out. What I need to know where should I use !important in this code to align the button to middle? Or will I need a new css element to do that?
<!-- Awesome button css Start -->
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>
Add *{box-sizing:border-box;} to ur css
<!-- Awesome button css Start -->
*{box-sizing:border-box;}
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>
Use this CSS to center align the button
.btn-green {
background-color: #1AAB8A;
position: relative;
left: 50%;
transform: translateX(-50%);
}
<!-- Awesome button css Start -->.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
position: relative;
left: 50%;
transform: translateX(-50%);
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
position: relative;
left: 50%;
transform: translateX(-50%);
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,
.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,
.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,
.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->.btn-green {}
<div class="btn-margin">
<a class="btn btn-green" href="https://myneobuxportal.blogspot.com/p/answer-gamer-quiz-v2.html">
Click Here To See Answers
</a>
</div>
add one parent div and set this div text-align: center;
<!-- Awesome button css Start -->
.demo{
text-align: center;
}
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
<!-- Awesome button css End -->
<div class="Demo">
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>
</div>
In the end the problem was with the comment :(
I used html comment in css. That's why this happened. Thanks #CharuMaheshwari for mentioning that out. Also another thanks for other 3 answers. All of them worked.
With #CharuMaheshwari help this is the code I decided to use.
/* Awesome button css Start */
.btn-margin {
margin-top: 1.6rem;
box-sizing: inherit;
text-align: center;
}
.btn {
-webkit-tap-high!importantr: transparent;
border-radius: 2px;
box-shadow: rgba(0, 0, 0, 0.14) 0 3px 3px 0, rgba(0, 0, 0, 0.12) 0 1px 7px 0, rgba(0, 0, 0, 0.2) 0 3px 1px -1px;
box-sizing: inherit;
color: white !important;
cursor: pointer;
display: inline-block;
height: auto;
letter-spacing: 0.5px;
line-height: 42px;
pointer-events: all;
position: relative;
text-decoration-line: none;
vertical-align: middle;
font-size: 1.6em;
padding: 0 2em;
transition: 800ms ease all;
}
.btn-green {
background-color: #1AAB8A;
}
.btn-green:hover {
background-color: #fff;
color: #1AAB8A !important;
}
.btn:before,.btn:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 2px;
width: 0;
transition: 400ms ease all;
}
.btn:after {
right: inherit;
top: inherit;
left: 0;
bottom: 0;
}
.btn-green:before,.btn-green:after {
background: #1AAB8A;
}
.btn:hover:before,.btn:hover:after {
width: 100%;
transition: 800ms ease all;
}
/* Awesome button css End */
<div class="btn-margin">
<a class="btn btn-green" href="#">
Click Here To See Answers
</a>
</div>