Not able to align text left to the toggle button in html - html

I recently saw a video and created this toggle button code
HTML:
<div class="display">
<label class="label toggle">
<input type="checkbox" class="toggle_input" />
<div class="toggle-control"></div>
</label>
</div>
CSS:
html {
font-size: 16px;
box-sizing: border-box;
}
body {
font-size: 1em;
font-family: arial, sans-serif;
}
.display {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.toggle .toggle-control {
-webkit-transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
width: 4em;
height: 2em;
display: block;
border: 2px solid #8E8E93;
border-radius: 2em;
background-color: rgba(0, 0, 0, 0.06);
position: relative;
}
.toggle .toggle-control:after {
-webkit-transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
content: "";
width: 2em;
height: 2em;
display: block;
background-color: #fff;
border-radius: 50%;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 3px 2px rgba(0, 0, 0, 0.4);
position: absolute;
top: 0;
left: 0;
}
.toggle input {
display: none;
}
.toggle input:checked + .toggle-control {
border-color: #4cd964;
background-color: #4cd964;
}
.toggle input:checked + .toggle-control:after {
left: 2em;
}
Now the i want to add a text left aligned to the toggle button but i am not able to do it.
Expected OUTPUT:
(Some Text) (Toggle Button)
Please help

Change the display:block of the div (which causes it to be displayed on a line of its own) to display:inline-block.
And I added vertical-align:middle in this example, but it's up to you how to want the controls to line out!
html {
font-size: 16px;
box-sizing: border-box;
}
body {
font-size: 1em;
font-family: 'Arial', sans-serif;
}
.display {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.toggle .toggle-control {
-webkit-transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
width: 4em;
height: 2em;
display: inline-block; /* changed */
border: 2px solid #8E8E93;
border-radius: 2em;
background-color: rgba(0, 0, 0, 0.06);
position: relative;
vertical-align:middle; /* new; can be removed if desired */
}
.toggle .toggle-control:after {
-webkit-transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
transition: 0.3s cubic-bezier(0.98, 0.99, 1, 0.99);
content: "";
width: 2em;
height: 2em;
background-color: #fff;
border-radius: 50%;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 3px 2px rgba(0, 0, 0, 0.4);
position: absolute;
top: 0;
left: 0;
}
.toggle input {
display: none;
}
.toggle input:checked + .toggle-control {
border-color: #4cd964;
background-color: #4cd964;
}
.toggle input:checked + .toggle-control:after {
left: 2em;
}
<div class="display">
<label class="label toggle">
Some text
<input type="checkbox" class="toggle_input" />
<div class="toggle-control"></div>
</label>
</div>

Related

Force transition to complete on hover CSS

I have created a button. When the user hovers over it, a small red arrow fades in beneath it.
The transition time is 400ms. When I hover over the button for less than 400ms, I would like the red arrow to complete its full transition before fading out.
This gif shows the full transition, followed by the undesired behaviour.
#import url('https://fonts.googleapis.com/css2?family=M+PLUS+1p&display=swap');
:root {
--init-bubble-padding: 0px;
--bubble-padding: 10px;
--triangle-height: 12px;
--transition-delay: 0ms;
--transition-time: 400ms;
}
* {
font-family: 'M PLUS 1p', Verdana, Geneva, Tahoma, sans-serif;
z-index: 100;
}
.popup-button-ctr {
display: inline-block;
position: relative;
outline: 0px solid red;
}
.button-ctr button {
background-color: rgba(30, 30, 30, 1);
border: none;
border-radius: 5px;
outline: 0px solid rgb(90, 90, 90);
font-weight: 900;
color: rgb(205, 205, 205);
padding: 8px 10px 8px 10px;
}
.button-ctr button:hover {
color: white;
cursor: pointer;
background-color: rgba(50, 50, 50, 1);
}
.triangle-up,
.triangle-right,
.triangle-down,
.triangle-left {
pointer-events: none;
display: relative;
position: absolute;
text-shadow: 1px 1px 10px rgba(21, 36, 63, 0.4);
z-index: 50;
color: rgba(255, 0, 0, 1);
background-color: transparent;
opacity: 0;
visibility: hidden;
transform: scale(0);
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
transition-property: opacity, visibility, transform, top, right, bottom, left;
}
.popup-posr-up,
.popup-posr-right,
.popup-posr-down,
.popup-posr-left {
width: 0; height: 0;
z-index: 150;
position: absolute;
}
.popup-posr-down {
left: 50%;
}
.popup-button-ctr .triangle-down {
transform: rotate(0deg) translateX(-50%);
top: var(--init-bubble-padding);
}
.popup-button-ctr:hover .triangle-down {
transform: rotate(0deg) translateX(-50%);
opacity: 1;
visibility: visible;
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
top: var(--bubble-padding);
<div class="popup-button-ctr">
<div class="button-ctr">
<button>
<div style="font-size: 30px">
Emoji Button
</div>
This button has emojis 😛 <br />
Let's ROCK 🤘 🤠 🎸
</button>
</div>
<div class="popup-posr-down">
<div class="triangle-down">
â–²
</div>
</div>
</div>
Is there any way to force transitions to complete?
Many thanks - Oli
a CSS only solution by adding this code:
.popup-button-ctr:hover::before {
content:"";
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
animation:h calc(var(--transition-time) + var(--transition-delay)) forwards;
}
#keyframes h {
99.9% {bottom:0;}
100% {bottom:100%}
}
This will increase the hoverable area to the whole screen to make sure you will keep the hover effect until the end of transition.
#import url('https://fonts.googleapis.com/css2?family=M+PLUS+1p&display=swap');
:root {
--init-bubble-padding: 0px;
--bubble-padding: 10px;
--triangle-height: 12px;
--transition-delay: 0ms;
--transition-time: 400ms;
}
* {
font-family: 'M PLUS 1p', Verdana, Geneva, Tahoma, sans-serif;
z-index: 100;
}
.popup-button-ctr {
display: inline-block;
position: relative;
outline: 0px solid red;
}
.button-ctr button {
background-color: rgba(30, 30, 30, 1);
border: none;
border-radius: 5px;
outline: 0px solid rgb(90, 90, 90);
font-weight: 900;
color: rgb(205, 205, 205);
padding: 8px 10px 8px 10px;
}
.button-ctr button:hover {
color: white;
cursor: pointer;
background-color: rgba(50, 50, 50, 1);
}
.triangle-up,
.triangle-right,
.triangle-down,
.triangle-left {
pointer-events: none;
display: relative;
position: absolute;
text-shadow: 1px 1px 10px rgba(21, 36, 63, 0.4);
z-index: 50;
color: rgba(255, 0, 0, 1);
background-color: transparent;
opacity: 0;
visibility: hidden;
transform: scale(0);
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
transition-property: opacity, visibility, transform, top, right, bottom, left;
}
.popup-posr-up,
.popup-posr-right,
.popup-posr-down,
.popup-posr-left {
width: 0;
height: 0;
z-index: 150;
position: absolute;
}
.popup-posr-down {
left: 50%;
}
.popup-button-ctr .triangle-down {
transform: rotate(0deg) translateX(-50%);
top: var(--init-bubble-padding);
}
.popup-button-ctr:hover .triangle-down {
transform: rotate(0deg) translateX(-50%);
opacity: 1;
visibility: visible;
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
top: var(--bubble-padding);
}
.popup-button-ctr:hover::before {
content:"";
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
animation:h calc(var(--transition-time) + var(--transition-delay)) forwards;
}
#keyframes h {
99.9% {bottom:0;}
100% {bottom:100%}
}
<div class="popup-button-ctr">
<div class="button-ctr">
<button>
<div style="font-size: 30px">
Emoji Button
</div>
This button has emojis 😛 <br />
Let's ROCK 🤘 🤠 🎸
</button>
</div>
<div class="popup-posr-down">
<div class="triangle-down">
â–²
</div>
</div>
</div>
In my solution, I propose animation by means of jquery, for event hover.
$('.popup-button-ctr').hover(function(){
$('.triangle-down').css("transform", "rotate(0deg) translateX(-50%)");
$('.triangle-down').css('opacity', '1');
$('.triangle-down').css('visibility', 'visible');
$('.triangle-down').css('transition', '400ms');
$('.triangle-down').css('transition-delay', '0s');
$('.triangle-down').css('top', '10px');
}, function() {
setTimeout(function() {
$('.triangle-down').css("transform", "rotate() translateX()");
$('.triangle-down').css('opacity', '');
$('.triangle-down').css('visibility', '');
$('.triangle-down').css('transition', '');
$('.triangle-down').css('transition-delay', '');
$('.triangle-down').css('top', '');
}, 400);
});
#import url('https://fonts.googleapis.com/css2?family=M+PLUS+1p&display=swap');
:root {
--init-bubble-padding: 0px;
--bubble-padding: 10px;
--triangle-height: 12px;
--transition-delay: 0ms;
--transition-time: 400ms;
}
* {
font-family: 'M PLUS 1p', Verdana, Geneva, Tahoma, sans-serif;
z-index: 100;
}
.popup-button-ctr {
display: inline-block;
position: relative;
outline: 0px solid red;
}
.button-ctr button {
background-color: rgba(30, 30, 30, 1);
border: none;
border-radius: 5px;
outline: 0px solid rgb(90, 90, 90);
font-weight: 900;
color: rgb(205, 205, 205);
padding: 8px 10px 8px 10px;
}
.button-ctr button:hover {
color: white;
cursor: pointer;
background-color: rgba(50, 50, 50, 1);
}
.triangle-up,
.triangle-right,
.triangle-down,
.triangle-left {
pointer-events: none;
display: relative;
position: absolute;
text-shadow: 1px 1px 10px rgba(21, 36, 63, 0.4);
z-index: 50;
color: rgba(255, 0, 0, 1);
background-color: transparent;
opacity: 0;
visibility: hidden;
transform: scale(0);
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
transition-property: opacity, visibility, transform, top, right, bottom, left;
}
.popup-posr-up,
.popup-posr-right,
.popup-posr-down,
.popup-posr-left {
width: 0; height: 0;
z-index: 150;
position: absolute;
}
.popup-posr-down {
left: 50%;
}
.popup-button-ctr .triangle-down {
transform: rotate(0deg) translateX(-50%);
top: var(--init-bubble-padding);
}
/*.popup-button-ctr:hover .triangle-down {
transform: rotate(0deg) translateX(-50%);
opacity: 1;
visibility: visible;
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
top: var(--bubble-padding);*/
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="popup-button-ctr">
<div class="button-ctr">
<button>
<div style="font-size: 30px">
Emoji Button
</div>
This button has emojis 😛 <br />
Let's ROCK 🤘 🤠 🎸
</button>
</div>
<div class="popup-posr-down">
<div class="triangle-down">
â–²
</div>
</div>
</div>
If you are looking for a vanillajs solution without using any library like jQuery -
mouseover and mouseout eventlisteners are used to add a class .visible with the desired css to the triangle on hover and remove the same class after 400ms on removing the mouse cursor, allowing enough time for the transition.
document.querySelector('.popup-button-ctr').addEventListener("mouseover", function(){
document.querySelector('.triangle-down').classList.add("visible");
});
document.querySelector('.popup-button-ctr').addEventListener("mouseout", function(){
setTimeout(function() {
document.querySelector('.triangle-down').classList.remove("visible");
}, 400);
});
#import url('https://fonts.googleapis.com/css2?family=M+PLUS+1p&display=swap');
:root {
--init-bubble-padding: 0px;
--bubble-padding: 10px;
--triangle-height: 12px;
--transition-delay: 0ms;
--transition-time: 400ms;
}
* {
font-family: 'M PLUS 1p', Verdana, Geneva, Tahoma, sans-serif;
z-index: 100;
}
.popup-button-ctr {
display: inline-block;
position: relative;
outline: 0px solid red;
}
.button-ctr button {
background-color: rgba(30, 30, 30, 1);
border: none;
border-radius: 5px;
outline: 0px solid rgb(90, 90, 90);
font-weight: 900;
color: rgb(205, 205, 205);
padding: 8px 10px 8px 10px;
}
.button-ctr button:hover {
color: white;
cursor: pointer;
background-color: rgba(50, 50, 50, 1);
}
.triangle-up,
.triangle-right,
.triangle-down,
.triangle-left {
pointer-events: none;
display: relative;
position: absolute;
text-shadow: 1px 1px 10px rgba(21, 36, 63, 0.4);
z-index: 50;
color: rgba(255, 0, 0, 1);
background-color: transparent;
opacity: 0;
visibility: hidden;
transform: scale(0);
transition: var(--transition-time) ease-in-out;
transition-delay: var(--transition-delay);
transition-property: opacity, visibility, transform, top, right, bottom, left;
}
.popup-posr-up,
.popup-posr-right,
.popup-posr-down,
.popup-posr-left {
width: 0; height: 0;
z-index: 150;
position: absolute;
}
.popup-posr-down {
left: 50%;
}
.popup-button-ctr .triangle-down {
transform: rotate(0deg) translateX(-50%);
top: var(--init-bubble-padding);
}
.visible{
transform : rotate(0deg) translateX(-50%);
opacity : 1;
visibility : visible;
transition : 400ms;
transition-delay : 0s;
top : 10px;
}
<div class="popup-button-ctr">
<div class="button-ctr">
<button>
<div style="font-size: 30px">
Emoji Button
</div>
This button has emojis 😛 <br />
Let's ROCK 🤘 🤠 🎸
</button>
</div>
<div class="popup-posr-down">
<div class="triangle-down">
â–²
</div>
</div>
</div>

Creating a switch toggle with a "yes" "no" that appears inside

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>

Click on any radio button to toggle switch

I would like to make the whole radio button clickable.
For example, when I click on the first one, it will toggle to 'OFF', and when I click again, it will switch back to 'ON', just like how normal toggle switch does.
Somehow it only will switch when I click on that specific radio button. You can see from my fiddle.
Fiddle
I appreciate your help. Thank you!
.switch {
background: white;
border-radius: 3px;
}
.switch-label {
position: relative;
z-index: 2;
float: left;
width: 58px;
line-height: 26px;
font-size: 11px;
color: rgba(255, 255, 255, 0.35);
text-align: center;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.45);
cursor: pointer;
}
.switch-label:active {
font-weight: bold;
}
.switch-label-No {
padding-left: 2px;
}
.switch-label-Yes {
padding-right: 2px;
}
.switch-input {
display: none;
}
.switch-input:checked + .switch-label {
font-weight: bold;
color: rgba(0, 0, 0, 0.65);
}
.switch-input:checked + .switch-label-Yes ~ .switch-selection {
left: 60px;
background-color:red;
/* Note: left: 50%; doesn't transition in WebKit */
}
.switch-selection {
position: absolute;
z-index: 1;
left: 2px;
display: block;
width: 58px;
height: 22px;
border-radius: 3px;
background-color: #65bd63;
-webkit-box-shadow: inset 0 1px rgba(255, 255, 255, 0.5), 0 0 2px rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px rgba(255, 255, 255, 0.5), 0 0 2px rgba(0, 0, 0, 0.2);
-webkit-transition: left 0.15s ease-out;
-moz-transition: left 0.15s ease-out;
-ms-transition: left 0.15s ease-out;
-o-transition: left 0.15s ease-out;
transition: left 0.15s ease-out;
}
<div class="switch">
<input type="radio" class="switch-input" name="view" value="1" id="week" checked>
<label for="week" class="switch-label switch-label-No">ON</label>
<input type="radio" class="switch-input" name="view" value="month" id="month">
<label for="month" class="switch-label switch-label-Yes">OFF</label>
<span class="switch-selection"></span>
</div>
Hope this will help you:
HTML:
<label class="switch">
<input type="checkbox">
<span class="slider"></span>
</label>
CSS:
.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}

CSS button not aligning correctly

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>

Cards won't be positionned correctly

Building a website with the framework Materialize.css and can't figure out how to get the cards to be properly positionned.
card-unpositionned-image
I want the cards to be positionned right under the parallax part (where it says parallax as header with a short paragraph under it) inline (so they are not separated block by block).
Code snippet in index.html
<section style="display:inline;">
<article class="card">
<header class="card__thumb">
<a href="#">
<img src="http://lorempicsum.com/futurama/370/235/2">
</a>
</header>
<div class="card__date">
<span class="card__date__day">12</span>
<span class="card__date__month">May</span>
</div>
<div class="card__body">
<div class="card__category">Photos</div>
<h2 class="card__title">Bender Should Not Be Allowed on TV</h2>
<div class="card__subtitle">A Head in the Polls</div>
<p class="card__description">
With a warning label this big, you know they gotta be fun! This is the worst part. The calm before the battle. No! The cat shelter's on to me. Yes, I saw. You were doing well, until everyone died. Daylight and everything.
</p>
</div>
<footer class="card__footer">
<span class="icon icon--time"></span>6 min
<span class="icon icon--comment"></span>39 comments
</footer>
</article>
<article class="card">
<header class="card__thumb">
<a href="#">
<img src="http://lorempicsum.com/futurama/370/235/2">
</a>
</header>
<div class="card__date">
<span class="card__date__day">12</span>
<span class="card__date__month">May</span>
</div>
<div class="card__body">
<div class="card__category">Photos</div>
<h2 class="card__title">Bender Should Not Be Allowed on TV</h2>
<div class="card__subtitle">A Head in the Polls</div>
<p class="card__description">
With a warning label this big, you know they gotta be fun! This is the worst part. The calm before the battle. No! The cat shelter's on to me. Yes, I saw. You were doing well, until everyone died. Daylight and everything.
</p>
</div>
<footer class="card__footer">
<span class="icon icon--time"></span>6 min
<span class="icon icon--comment"></span>39 comments
</footer>
</article>
</section>
Code in assets/css/style.css
* {
box-sizing: border-box; }
body {
font-family: Roboto;
font-size: 16px;
line-height: 1.4;
background-color: #d8e0e5; }
.card {
position: static;
overflow: hidden;
top: 50%;
left: 50%;
width: 370px;
-webkit-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background-color: #fff;
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1);
transition: box-shadow 0.3s; }
.card a {
color: inherit;
text-decoration: none; }
.card:hover {
box-shadow: 0px 0px 50px rgba(0, 0, 0, 0.3); }
.card__date {
position: absolute;
top: 20px;
right: 20px;
width: 45px;
height: 45px;
padding-top: 10px;
color: #FFF;
text-align: center;
line-height: 13px;
font-weight: bold;
background-color: #38c4a5;
border-radius: 50%; }
.card__date__day {
display: block;
font-size: 14px; }
.card__date__month {
display: block;
font-size: 10px;
text-transform: uppercase; }
.card__thumb {
height: 235px;
overflow: hidden;
background-color: #000;
transition: height 0.3s; }
.card__thumb img {
display: block;
opacity: 1;
transition: opacity 0.3s, -webkit-transform 0.3s;
transition: opacity 0.3s, transform 0.3s;
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1); }
.card:hover .card__thumb img {
opacity: 0.6;
-webkit-transform: scale(1.2);
-ms-transform: scale(1.2);
transform: scale(1.2); }
.card:hover .card__thumb {
height: 90px; }
.card__body {
position: relative;
padding: 20px;
height: 185px;
transition: height 0.3s; }
.card:hover .card__body {
height: 330px; }
.card__category {
position: absolute;
left: 0;
top: -25px;
height: 25px;
padding: 0 15px;
color: #FFF;
font-size: 11px;
line-height: 25px;
text-transform: uppercase;
background-color: #38c4a5; }
.card__title {
margin: 0;
padding: 0 0 10px 0;
font-size: 22px;
color: #000;
font-weight: bold; }
.card:hover .card__title {
-webkit-animation: titleBlur 0.3s;
animation: titleBlur 0.3s; }
.card__subtitle {
margin: 0;
padding: 0 0 10px 0;
font-size: 19px;
color: #38c4a5; }
.card:hover .card__subtitle {
-webkit-animation: subtitleBlur 0.3s;
animation: subtitleBlur 0.3s; }
.card__description {
position: absolute;
left: 20px;
right: 20px;
bottom: 65px;
margin: 0;
padding: 0;
color: #666C74;
font-size: 14px;
line-height: 27px;
opacity: 0;
transition: opacity 0.2s, -webkit-transform 0.2s;
transition: opacity 0.2s, transform 0.2s;
transition-delay: 0s;
-webkit-transform: translateY(25px);
-ms-transform: translateY(25px);
transform: translateY(25px); }
.card:hover .card__description {
opacity: 1;
transition-delay: 0.1s;
-webkit-transform: translateY(0);
-ms-transform: translateY(0);
transform: translateY(0); }
.card__footer {
position: absolute;
bottom: 20px;
left: 20px;
right: 20px;
font-size: 11px;
color: #A3A9AB; }
.card__footer .icon--comment {
margin-left: 12px; }
.icon {
display: inline-block;
vertical-align: middle;
margin-right: 2px; }
.icon--comment {
background: url(https://www.grafikart.fr/demo/CSS3/cardui/img/icon-comment.png);
width: 14px;
height: 14px;
margin-top: -2px; }
.icon--time {
background: url(https://www.grafikart.fr/demo/CSS3/cardui/img/icon-time.png);
width: 10px;
height: 17px;
margin-top: -3px; }
#-webkit-keyframes titleBlur {
0% {
opacity: 0.6;
text-shadow: 0px 5px 5px rgba(0, 0, 0, 0.6); }
100% {
opacity: 1;
text-shadow: 0px 5px 5px transparent; } }
#keyframes titleBlur {
0% {
opacity: 0.6;
text-shadow: 0px 5px 5px rgba(0, 0, 0, 0.6); }
100% {
opacity: 1;
text-shadow: 0px 5px 5px transparent; } }
#-webkit-keyframes subtitleBlur {
0% {
opacity: 0.6;
text-shadow: 0px 5px 5px rgba(56, 196, 165, 0.6); }
100% {
opacity: 1;
text-shadow: 0px 5px 5px rgba(56, 196, 165, 0); } }
#keyframes subtitleBlur {
0% {
opacity: 0.6;
text-shadow: 0px 5px 5px rgba(56, 196, 165, 0.6); }
100% {
opacity: 1;
text-shadow: 0px 5px 5px rgba(56, 196, 165, 0); } }
Tried wrapping the cards with a section tag giving him a style of display: inline but didn't change the thing.
Here's a schema of how I would like it to work:
schema-how-it-works