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>
Related
I just downloaded an HTML and CSS template online and want to modify the code to adjust the hamburger menu icon to the right and have the menu slide from the right side but I had no idea about which part I should change
I have attached a screenshot of the interface below for reference. Thanks!
/*menu*/
#menuToggle
{
display: block;
position: relative;
top: 50px;
left: 50px;
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a
{
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
#menuToggle a:hover
{
color: tomato;
}
#menuToggle input
{
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0; /* hide this */
z-index: 2; /* and place it over the hamburger */
-webkit-touch-callout: none;
}
/*
* Just a quick hamburger
*/
#menuToggle span
{
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
background 0.5s cubic-bezier(0.77,0.2,0.05,1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child
{
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2)
{
transform-origin: 0% 100%;
}
/*
* Transform all the slices of hamburger
* into a crossmark.
*/
#menuToggle input:checked ~ span
{
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #ffffff;
}
/*
* But let's hide the middle one.
*/
#menuToggle input:checked ~ span:nth-last-child(3)
{
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*
* Ohyeah and the last one should go the other direction
*/
#menuToggle input:checked ~ span:nth-last-child(2)
{
transform: rotate(-45deg) translate(0, -1px);
}
/*
* Make this absolute positioned
* at the top left of the screen
*/
#menu
{
position: absolute;
width: 300px;
margin: -100px 0 0 -50px;
padding: 50px;
padding-top: 125px;
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/* to stop flickering of text in safari */
transform-origin: 0% 0%;
transform: translate(-100%, 0);
transition: transform 0.5s cubic-bezier(0.77,0.2,0.05,1.0);
}
#menu li
{
padding: 10px 0;
font-size: 22px;
}
/*
* And let's slide it in from the left
*/
#menuToggle input:checked ~ ul
{
transform: none;
}
/*----------------------------------menu----------------------------*/
.section {
position: relative;
height: 100vh;
}
.section .section-center {
position: absolute;
top: 50%;
left: 0;
right: 0;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
#booking {
font-family: 'Montserrat', sans-serif;
background-image: url('../img/dog.jpeg');
background-size: cover;
background-position: center;
}
#booking::before {
content: '';
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: rgba(143, 215, 230, 0.6);
}
.booking-form {
background-color: #fff;
padding: 60px 20px;
-webkit-box-shadow: 0px 5px 20px -5px rgba(0, 0, 0, 0.3);
box-shadow: 0px 5px 20px -5px rgba(0, 0, 0, 0.3);
border-radius: 4px;
}
.booking-form .form-group {
position: relative;
margin-bottom: 30px;
}
.booking-form .form-control {
background-color: #ebecee;
border-radius: 4px;
border: none;
height: 40px;
-webkit-box-shadow: none;
box-shadow: none;
color: #3e485c;
font-size: 14x;
}
.booking-form .form-control::-webkit-input-placeholder {
color: rgba(62, 72, 92, 0.3);
}
.booking-form .form-control:-ms-input-placeholder {
color: rgba(62, 72, 92, 0.3);
}
.booking-form .form-control::placeholder {
color: rgba(62, 72, 92, 0.3);
}
.booking-form input[type="date"].form-control:invalid {
color: rgba(62, 72, 92, 0.3);
}
.booking-form select.form-control {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.booking-form select.form-control+.select-arrow {
position: absolute;
right: 0px;
bottom: 4px;
width: 40px;
line-height: 32px;
height: 32px;
text-align: center;
pointer-events: none;
color: rgba(62, 72, 92, 0.3);
font-size: 14px;
}
.booking-form select.form-control+.select-arrow:after {
content: '\279C';
display: block;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
.booking-form .form-label {
display: inline-block;
color: #3e485c;
font-weight: 700;
margin-bottom: 6px;
margin-left: 7px;
}
.booking-form .submit-btn {
display: inline-block;
color: #fff;
background-color: #1e62d8;
font-weight: 700;
padding: 14px 30px;
border-radius: 4px;
border: none;
-webkit-transition: 0.2s all;
transition: 0.2s all;
}
.booking-form .submit-btn:hover,
.booking-form .submit-btn:focus {
opacity: 0.9;
}
.booking-cta {
margin-top: 80px;
margin-bottom: 30px;
}
.booking-cta h1 {
font-size: 52px;
text-transform: uppercase;
color: #fff;
font-weight: 700;
}
.booking-cta p {
font-size: 20px;
color: rgba(255, 255, 255, 0.8);
}
footer {
position: relative;
height: 0px;
width: 100%;
background-color: #333333;
}
p.copyright {
position: absolute;
width: 100%;
color: #fff;
line-height: 40px;
font-size: 0.7em;
text-align: center;
bottom:0;
}
HTML Code:
<nav role="navigation">
<div id="menuToggle">
<!--
A fake / hidden checkbox is used as click reciever,
so you can use the :checked selector on it.
-->
<input type="checkbox" />
<!--
Some spans to act as a hamburger.
They are acting like a real hamburger,
not that McDonalds stuff.
-->
<span></span>
<span></span>
<span></span>
<ul id="menu">
<li>Home</li>
<li>About</li>
<li>Info</li>
<li>Contact</li>
</ul>
</div>
</nav>
<div id="booking" class="section">
<div class="section-center">
<div class="container">
<div class="row">
<div class="col-md-7 col-md-push-5">
<div class="booking-cta">
<h1>Bring Your Pet to Work</h1>
<p>Caring and Loving Pet service
</p>
</div>
</div>
<div class="col-md-4 col-md-pull-7">
<div class="booking-form">
<form>
<div class="form-group">
<span class="form-label">Where do you work? </span>
<input class="form-control" type="text" placeholder="Enter an address or zipcode">
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Drop off</span>
<input class="form-control" type="date" required>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<span class="form-label">Pick up</span>
<input class="form-control" type="date" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<span class="form-label">Pet?</span>
<select class="form-control">
<option>Cat</option>
<option>Dog</option>
<option>Others</option>
</select>
<span class="select-arrow"></span>
</div>
</div>
<div class="col-sm-4">
<div class="form-group">
<span class="form-label">Service</span>
<select class="form-control">
<option>Day Care</option>
<option>Boarding</option>
<option>Sitting</option>
</select>
<span class="select-arrow"></span>
</div>
</div>
</div>
<div class="form-btn">
<button class="submit-btn">Check availability</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
//about the white space try set the margin-top of the body at 0;
//about the the hamberger icon try this:
nav {
display:flex;
flex-direction: flex-end; }
To move the hamburger to the right side, make sure your #menuToggle position is fixed or absolute, then removeleft: 50px; and add right: 50px; and if you want more top space you can increase top attribute value, ex: top: 100px; or top: 0; if you don't want any top space.
I've commented the CSS bellow, in case you were wondering what i've changed.
Here is the CSS code you should use: (I've tested it and it's working for me)
#menuToggle {
display: block;
position: fixed;
top: 50px; /** NOTE: decrease The pixels if want less space */
right: 50px;/** NOTE: Change This line */
z-index: 1;
-webkit-user-select: none;
user-select: none;
}
#menuToggle a {
text-decoration: none;
color: #232323;
transition: color 0.3s ease;
}
#menuToggle a:hover {
color: tomato;
}
#menuToggle input {
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0;
/* hide this */
z-index: 2;
/* and place it over the hamburger */
-webkit-touch-callout: none;
}
/*
* Just a quick hamburger
*/
#menuToggle span {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0),
background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0),
opacity 0.55s ease;
}
#menuToggle span:first-child {
transform-origin: 0% 0%;
}
#menuToggle span:nth-last-child(2) {
transform-origin: 0% 100%;
}
/*
* Transform all the slices of hamburger
* into a crossmark.
*/
#menuToggle input:checked~span {
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #ffffff;
}
/*
* But let's hide the middle one.
*/
#menuToggle input:checked~span:nth-last-child(3) {
opacity: 0;
transform: rotate(0deg) scale(0.2, 0.2);
}
/*
* Ohyeah and the last one should go the other direction
*/
#menuToggle input:checked~span:nth-last-child(2) {
transform: rotate(-45deg) translate(0, -1px);
}
/*
* Make this absolute positioned
* at the top left of the screen
*/
#menu {
position: absolute;
width: 300px;
margin: -100px 0 0;/** NOTE: Change this line */
padding: 50px;
padding-top: 125px;
right: -50px; /*NOTE: Add this line */
background: #ededed;
list-style-type: none;
-webkit-font-smoothing: antialiased;
/* to stop flickering of text in safari */
transform-origin: 0% 0%;
transform: translateX(100%);/** NOTE: Change this line */
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0);
}
#menu li {
padding: 10px 0;
font-size: 22px;
}
/*
* And let's slide it in from the left
*/
#menuToggle input:checked~ul {
transform: none;
}
/*----------------------------------menu----------------------------*/
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>
I came across this pen which is a really cool floating share button. Here's the link:
http://codepen.io/koenigsegg1/pen/pjeJvb
HTML
#import url(https://fonts.googleapis.com/css?family=Roboto:100,200,300,400,500);
body {
background: #00BCD4;
min-height: 100vh;
overflow: hidden;
font-family: Roboto;
color: #fff;
}
h1 {
font: 200 60px Roboto;
text-align: center;
}
p.credits {
text-align: center;
margin-top: 100px;
}
.credits img {
border-radius: 50%;
width: 100px;
}
.container {
bottom: 0;
position: fixed;
margin: 1em;
right: 0px;
}
.buttons {
box-shadow: 0px 5px 11px -2px rgba(0, 0, 0, 0.18), 0px 4px 12px -7px rgba(0, 0, 0, 0.15);
border-radius: 50%;
display: block;
width: 56px;
height: 56px;
margin: 20px auto 0;
position: relative;
-webkit-transition: all .1s ease-out;
transition: all .1s ease-out;
}
.buttons:active,
.buttons:focus,
.buttons:hover {
box-shadow: 0 0 4px rgba(0, 0, 0, .14), 0 4px 8px rgba(0, 0, 0, .28);
}
.buttons:not(:last-child) {
width: 40px;
height: 40px;
margin: 20px auto 0;
opacity: 0;
-webkit-transform: translateY(50px);
-ms-transform: translateY(50px);
transform: translateY(50px);
}
.container:hover .buttons:not(:last-child) {
opacity: 1;
-webkit-transform: none;
-ms-transform: none;
transform: none;
margin: 15px auto 0;
}
/* Unessential styling for sliding up buttons at differnt speeds */
.buttons:nth-last-child(1) {
-webkit-transition-delay: 25ms;
transition-delay: 25ms; background-image: url('http://cbwconline.com/IMG/Share.svg'); background-size: contain; } .buttons:not(:last-child):nth-last-child(2) { -webkit-transition-delay: 50ms; transition-delay: 20ms; background-image: url('http://cbwconline.com/IMG/Facebook-Flat.png');
background-size: contain; } .buttons:not(:last-child):nth-last-child(3) { -webkit-transition-delay: 75ms; transition-delay: 40ms; background-image: url('http://cbwconline.com/IMG/Twitter-Flat.png'); background-size: contain; } .buttons:not(:last-child):nth-last-child(4)
{
-webkit-transition-delay: 100ms; transition-delay: 60ms; background-image: url('http://cbwconline.com/IMG/Google%20Plus.svg'); background-size: contain; } /* Show tooltip content on hover *
[tooltip]: before {
bottom: 25%;
font-family: arial;
font-weight: 600;
border-radius: 2px;
background: #585858;
color: #fff;
content: attr(tooltip);
font-size: 12px;
visibility: hidden;
opacity: 0;
padding: 5px 7px;
margin-right: 12px;
position: absolute;
right: 100%;
white-space: nowrap;
}
[tooltip]:hover:before,
[tooltip]:hover:after {
visibility: visible;
opacity: 1;
}
<body>
<h1>Simple Share FAB</h1>
<p class="credits">
<a href="http://codepen.io/koenigsegg1" target="_blank">
<img src="http://s3-us-west-2.amazonaws.com/s.cdpn.io/343394/profile/profile-80_3.jpg" />
</a>
<br />Pen by Kyle Lavery (#koenigsegg1)</p>
<nav class="container">
<a class="buttons" tooltip="Share" href="#"></a>
</nav>
</body>
In the demo, you can see that if you hover on the share button, the other buttons pop up, and each button has a different tooltip.
Now, what I want to do is make all those tooltips visible as soon as the share button is hovered, instead of displaying them when that particular button is hovered. Is it possible to do using pure css? I can't seem to figure it out.
It is simply a matter of toggling the visibility value of the CSS elements for [tooltip] attribute.
Also, remove the [tooltip]:hover:before and [tooltip]:hover:after properties.
#import url(https://fonts.googleapis.com/css?family=Roboto:100,200,300,400,500);
body {
background: #00BCD4;
min-height: 100vh;
overflow: hidden;
font-family: Roboto;
color: #fff;
}
h1 {
font: 200 60px Roboto;
text-align: center;
}
p.credits {
text-align: center;
margin-top: 100px;
}
.credits img {
border-radius: 50%;
width: 100px;
}
.container {
bottom: 0;
position: fixed;
margin: 1em;
right: 0px;
}
.buttons {
box-shadow: 0px 5px 11px -2px rgba(0, 0, 0, 0.18), 0px 4px 12px -7px rgba(0, 0, 0, 0.15);
border-radius: 50%;
display: block;
width: 56px;
height: 56px;
margin: 20px auto 0;
position: relative;
-webkit-transition: all .1s ease-out;
transition: all .1s ease-out;
}
.buttons:active,
.buttons:focus,
.buttons:hover {
box-shadow: 0 0 4px rgba(0, 0, 0, .14), 0 4px 8px rgba(0, 0, 0, .28);
}
.buttons:not(:last-child) {
width: 40px;
height: 40px;
margin: 20px auto 0;
opacity: 0;
-webkit-transform: translateY(50px);
-ms-transform: translateY(50px);
transform: translateY(50px);
}
.container:hover .buttons:not(:last-child) {
opacity: 1;
-webkit-transform: none;
-ms-transform: none;
transform: none;
margin: 15px auto 0;
}
/* Unessential styling for sliding up buttons at differnt speeds */
.buttons:nth-last-child(1) {
-webkit-transition-delay: 25ms;
transition-delay: 25ms;
background-image: url('http://cbwconline.com/IMG/Share.svg');
background-size: contain;
}
.buttons:not(:last-child):nth-last-child(2) {
-webkit-transition-delay: 50ms;
transition-delay: 20ms;
background-image: url('http://cbwconline.com/IMG/Facebook-Flat.png');
background-size: contain;
}
.buttons:not(:last-child):nth-last-child(3) {
-webkit-transition-delay: 75ms;
transition-delay: 40ms;
background-image: url('http://cbwconline.com/IMG/Twitter-Flat.png');
background-size: contain;
}
.buttons:not(:last-child):nth-last-child(4) {
-webkit-transition-delay: 100ms;
transition-delay: 60ms;
background-image: url('http://cbwconline.com/IMG/Google%20Plus.svg');
background-size: contain;
}
/* Show tooltip content on hover */
[tooltip]:before {
bottom: 25%;
font-family: arial;
font-weight: 600;
border-radius: 2px;
background: #585858;
color: #fff;
content: attr(tooltip);
font-size: 12px;
/*
visibility: hidden;
opacity: 0;
*/
padding: 5px 7px;
margin-right: 12px;
position: absolute;
right: 100%;
white-space: nowrap;
}
<body>
<h1>Simple Share FAB</h1>
<p class="credits">
<a href="http://codepen.io/koenigsegg1" target="_blank">
<img src="http://s3-us-west-2.amazonaws.com/s.cdpn.io/343394/profile/profile-80_3.jpg" />
</a>
<br />Pen by Kyle Lavery (#koenigsegg1)</p>
<nav class="container">
<a class="buttons" tooltip="Share" href="#"></a>
</nav>
</body>
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
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>