I am using scss and trying to hide an icon and when I hover the button I want the icon to display. I also want to animate it so I can't use display:none as I believe you can't animate that. So I have tried to use opacity and visibility.
I have 2 problems. Firstly, The text in the button is not centered because the icon is there in an invisible state yet when you go to dev tools you can still see it there. Secondly, the icon does not appear on hover.
.btn {
text-transform: uppercase;
text-decoration: none;
padding: 1.5rem 4rem;
display: inline-block;
font-size: 1.6rem;
box-shadow: 0 1rem 2rem rgba($color-black, .2);
&--primary {
background-color: $color-primary;
color: $color-white;
transition: all .2s;
&__icon {
visibility: hidden;
opacity: 0;
}
&:hover {
transform: translateY(-2px);
&__icon {
visibility: visible;
opacity: 1;
}
}
}
}
Discover More <i class="btn--primary__icon icon-basic-clockwise"></i>
I think the problem is that your icon is displayed inline with zero content. I think you might need to change the icon to display: inline-block; and give it some dimensions. You'll want to set the dimensions to 0px when the icon should not be visible.
I converted your code from SCSS to CSS and replaced the $variables with actual CSS colors to make a working snippet...
.btn {
text-transform: uppercase;
text-decoration: none;
padding: 1.5rem 4rem;
display: inline-block;
font-size: 1.6rem;
box-shadow: 0 1rem 2rem rgba(0,0,0, .2);
width: 240px;
}
.btn--primary {
background-color: red;
color: white;
transition: all .2s;
}
.btn--primary__icon {
display: inline-block;
width: 0px;
height: 0px;
visibility: hidden;
opacity: 0;
}
.btn--primary:hover {
transform: translateY(-2px);
}
.btn--primary:hover .btn--primary__icon {
width: 20px;
height: 20px;
background-color: blue;
visibility: visible;
opacity: 1;
}
<a href="#" class="btn btn--primary">
Discover More
<i class="btn--primary__icon icon-basic-clockwise"></i>
</a>
Related
I wanna to change the background-color title on hover and not when is not hover.
The problem is when I hover the element the title remains with light grey color(I think is default value color). I want to change the background in black color
<a class="popover-title" data-toggle="tooltip" data-trigger="hover"
title="test"
popover-append-to-body="true">
with this style
.myStyle{
max-width: 200px;
padding: 0.25rem 0.5rem;
color: #fff;
text-align: center;
background-color: black;
border-radius: 0.25rem;
}
SOLVED
I found a solution
[data-title]:hover:after {
opacity: 1;
transition: all 0.1s ease 0.5s;
visibility: visible;
}
[data-title]:after {
content: attr(data-title);
max-width: 200px;
background-color: #000;
color: #fff;
position: absolute;
text-align: center;
padding: 0.25rem 0.5rem;
border-radius: 0.25rem;
font-style: normal;
font-weight: 400;
line-height: 1.5;
z-index: 99999;
visibility: hidden;
}
[data-title] {
position: relative;
}
But the problem is when I want to put the translate it doesnt work and the tooltip returns transparant
<a class="font-weight-bold font-xs btn-block text-muted" data-toggle="tooltip" data-placement="bottom"
[attr.data-title]="'test' | translate"
popover-append-to-body="true">
You could use conventional CSS for this.
.popover-title:hover {
background-color: black;
}
For hover you need to write css with :hover
For you the code should be as below:
.myStyle:hover {
max-width: 200px;
padding: 0.25rem 0.5rem;
color: #fff;
text-align: center;
background-color: black;
border-radius: 0.25rem;
}
You are targeting wrong class. Try this
.popover-title:hover{
color: #000;
background-color: #fff;
}
Change the color and background-color as you want
This will help.
.popover-title:hover {
max-width: 200px;
padding: 0.25rem 0.5rem;
color: green;
text-align: center;
background-color: green;
border-radius: 0.25rem;
}
apply background-color property for 'popover-title' class like below.
.popover-title:hover{
background-color: #fff;
}
If above propery is overwritten use !important.
.popover-title:hover{
background-color: #fff!important;
}
Tooltips rely on the 3rd party library Tether for positioning. You must include propper.min.js or any other Library
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"> </script>
<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
I have been playing around trying to get a nice looking drag and drop control on my site and have come across this upload control.
MDBootstrap File Upload
I have found out that removing the class named 'file-field' will cause the normal file input to show.
My question is, what is it that is causing the file input control to dissapear when this class is reapplied, as when I remove all styles from the class using Chrome DevTools by unticking them, it makes no difference.
Thanks.
By using the Chrome developer tools, you can inspect the element and you will see the styles involved.
Here is a snippet using the CSS styles involved to get that effect, by removing the class 'file-field' the control will show because the current css styles are applying opacity 0, making it transparent within a fancy-styled button.
.md-form {
position: relative;
margin-top: 1.5rem;
margin-bottom: 1.5rem;
}
.btn {
box-shadow: 0 2px 5px 0 rgba(0,0,0,.16), 0 2px 10px 0 rgba(0,0,0,.12);
padding: .84rem 2.14rem;
font-size: .81rem;
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
margin: .375rem;
border: 0;
border-radius: .125rem;
cursor: pointer;
text-transform: uppercase;
white-space: normal;
word-wrap: break-word;
color: inherit;
}
.btn-mdb-color {
background-color: #59698d!important;
color: #fff;
}
.btn-rounded {
border-radius: 10em;
}
.waves-effect {
position: relative;
cursor: pointer;
overflow: hidden;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-tap-highlight-color: transparent;
}
.float-left {
float: left!important;
}
.file-field {
position: relative
}
.file-field .file-path-wrapper {
overflow: hidden;
padding-left: 10px;
height: 2.5rem
}
.file-field input.file-path {
width: 100%;
height: 36px
}
.file-field .btn {
float: left
}
.file-field span {
cursor: pointer
}
.file-field input[type=file] {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
width: 100%;
margin: 0;
padding: 0;
cursor: pointer;
opacity: 0
}
.file-field input[type=file]::-webkit-file-upload-button {
display: none
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="md-form">
<div class="file-field">
<div class="d-flex justify-content-center">
<div class="btn btn-mdb-color btn-rounded float-left waves-effect waves-light">
<span>Choose file</span>
<input type="file">
</div>
</div>
</div>
</form>
Please note that the order of the CSS styles matters
I am confused with these button animation codes. These codes produce a pulsating effect button, but I am having difficult time interpret how they work together or what is under the hood.
<div >
btn
</div>
style.css:
.btn:link,
.btn:visited {
position: relative;
border-radius: 10rem;
display: inline-block;
margin-top: 6rem;
text-transform: uppercase;
text-decoration: none;
padding: 1.5rem 4rem;
transition: all 1.2s;
}
.btn:hover {
transform: translateY(-.3rem);
box-shadow: 0 1rem 2rem rgba(0, 0, 0, .3);
}
.btn:active {
transform: translateY(-.1rem);
box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .2);
}
.btn--white {
background-color: #fff;
color: #777;
}
.btn--white::after {
background-color: #fff;
}
.btn::after {
content: "";
display: inline-block;
height: 100%;
width: 100%;
border-radius: 10rem;
position: absolute;
top: 0;
left: 0;
z-index: -1;
transition: all .2s;
}
.btn:hover::after {
transform: scaleX(1.4) scaleY(1.6);
opacity: 0;
}
My main confusions are:
-- How do I read ::before/after use plain English, with .btn::after? Can I read it as: after running .btn code, run these code here? or with .btn--white::after { background-color: #fff;} I can read: after .btn--white executed, paint background white?
-- with .btn::after we created empty btn box right behind the original link button, when we use .btn:hover::after isn't the mouse pointer suppose to hover on the original button link instead of the empty button because of Z-index?
-- How does pulsating effect was rendered here? how does the .btn--white::after get called for constantly repainting the empty button?
I have button transformation on hover in my custom stylesheet. It allows me to create button from <a href> or <div>. During this transformation font is blinking in strange way. Could you kindly tell me why and how to solve it?
Here is the scss code:
https://gist.github.com/rafpiek/7e1b2df5690baa3b02e88eee10adfb98
and the video:
https://www.youtube.com/watch?v=4c4D96FukuQ&feature=youtu.be
.button {
text-decoration: none;
color: #ECECEC;
font-size: 20px;
height: 40px;
width: 100px;
background: #B3595F;
display: inline-block;
transition: all 0.30s linear;
display: flex;
justify-content: center;
align-items: center;
margin: 5px 3px;
cursor: pointer;
border-radius: 6px;
user-select: none;
font-weight: bold;
}
.button:-webkit-any-link {
color: #ECECEC;
}
.button:hover {
transform: scale(1.07);
color: #ECECEC;
}
.button:active, .button:focus, .button:visited {
text-decoration: none;
color: #ECECEC;
}
.button.blue {
background-color: #2C92FF;
}
.button.red {
background-color: #FF2113;
}
.button.green {
background-color: #1EBE32;
}
<button class="button">button</button>
Try this in .button:
-webkit-font-smoothing: antialiased;
This is caused AFAIK from the browser changing the text antialias type during the animation (new GPU implicit layer).
More info on causes and fixes here -> How to prevent Webkit text rendering change during CSS transition
Can be reduced using perspective and 3d scale:
transform: perspective(1px) scale3d(1.07,1.07,1);
<style>
.button {
position: relative;
background-color: #41A0BF;
border: none;
font-size: 20px;
color: #FFFFFF;
padding: 15px;
width: 120px;
text-align: center;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
}
.button:after {
content: "";
background: #69D2F5;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -20px!important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s
}
.button:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
}
</style>
<button class="button">Home</button>
How to put link in button?
i tried everything codes available in google but still error in my website
i dont know whats the best code for this
thanks for someone who wants to teach me.
No. Its not possible to add link through css. But you can use jquery
$('.case').each(function() {
var link = $(this).html();
$(this).contents().wrap('');
});
I'll suggest to add anchor tag if you want to add link.
Home
Add link in "#". It'll work.
Four different possibilities to a button become a link (CSS isn't an option):
.button {
position: relative;
background-color: #41A0BF;
border: none;
font-size: 20px;
color: #FFFFFF;
padding-top: 15px;
padding-bottom: 15px;
width: 120px;
text-align: center;
overflow: hidden;
cursor: pointer;
display: inline-block;
text-decoration: none;
}
a, a:active, a:visited, a:focus {
text-decoration: none;
color: white;
font-family: arial, sans-serif;
}
Javascript:<br>
<button class="button" onClick="window.location.href = 'http://example.com'">click</button><br><br>
Inner link:<br>
<button class="button">click</button><br><br>
Wrapper link:<br>
<button class="button">click</button><br><br>
Fake button:<br>
<a href="http://example.com" class=button>click</a>
Please try this:
<button class="button">Home</button>
I think its the easy way to do it.
.button {
position: relative;
background-color: #41A0BF;
border: none;
font-size: 20px;
color: #FFFFFF;
padding: 15px;
width: 120px;
text-align: center;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
}
.button:after {
content: "";
background: #69D2F5;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -20px!important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s
}
.button:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
}
a{
text-decoration:none;
}
<button class="button">Home</button>
You can have the link as a button this way
home
Or if you using a css library like bootstrap
home