Hopefully this will be an easy thing to fix, but I have tried searching for an answer and nothing seems to fit.
I'm trying to make a hover effect on a button:
button {
min-width: 20vw;
max-width: 40vw;
border: none;
color: white;
font-size: 1.5vw;
padding: 15px 32px;
text-align: center;
text-decoration: none;
background-color: blue;
border-radius: 20px;
transition: 0.4s;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
.button:hover {
color: black;
background-color: lightcyan;
}
When I test this in a browser (vivaldi & edge) nothing changes. The test site is http://wyrdling.com/skulpturjagt by the way.
PS. I tried using the chrome developer tool, but I'm too much of a newb to figure out how to read it XD
Unless its a typo in your question, you use .button:hover. That will apply to elements with a class of hover. Swap it to button:hover
Here are some example plunkers.
Example 1:
button {
min-width: 20vw;
max-width: 40vw;
border: none;
color: white;
font-size: 1.5vw;
padding: 15px 32px;
text-align: center;
text-decoration: none;
background-color: blue;
border-radius: 20px;
transition: 0.4s;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
button:hover {
color: black;
background-color: lightcyan;
}
<button>My button.</button>
Example 2 :
.button {
min-width: 20vw;
max-width: 40vw;
border: none;
color: white;
font-size: 1.5vw;
padding: 15px 32px;
text-align: center;
text-decoration: none;
background-color: blue;
border-radius: 20px;
transition: 0.4s;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}
.button:hover {
color: black;
background-color: lightcyan;
}
<button class="button">My button</button>
Related
This question already has answers here:
How are the points in CSS specificity calculated
(7 answers)
Closed 1 year ago.
I have classes in css
.box {
background-color: white;
border: solid 5px white;
border-radius: 5px;
width: 90px;
height: 90px;
margin-top: 30px;
box-shadow: 0 8px 6px -6px #313131;
object-fit: fill;
position: relative;
cursor: pointer;
}
.active {
background-color: white;
border: solid 5px white;
border-radius: 5px;
width: 100px!important;
height: 100px!important;
margin-top: 20px;
box-shadow: 0 14px 6px -6px #313131;
position: relative;
animation: fadeactive 6s infinite;
}
.box:hover {
background-color: white;
border: solid 5px white;
border-radius: 5px;
width: 100px;
height: 100px;
margin-top: 20px;
box-shadow: 0 14px 6px -6px #313131;
object-fit: fill;
position: relative;
}
.box:hover.active .title {
display: none!important;
}
.title {
display: none;
position: relative;
font-size: 70%;
background: black;
color: white;
border-radius: 5px;
padding: 5px;
top: -40px;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
z-index: 2;
width: fit-content;
}
I use .box on some items, and sometimes I use .active as well (using both classes). If I do not use !important, the box size stays 90px instead of 100px. Also in .box:hover.active .title I need to use !important to make it work. What did I do wrong? How can I get rid of !important here?
Here in this example,
Without the !important, the color will be red since ID has most priority.
But since I gave !important to the span, it is taking that style.
#item1 {
color: red;
}
.item {
color: yellow;
}
span {
color: blue !important;
}
<span class='item' id='item1'>hi</span>
So I have button defined by the a-tag which says:
.button {
background: #aaaaaa;
padding: 20px 30px;
font-weight: bold;
color: #ffffff;
text-transform: uppercase;
border-radius: 15px;
box-shadow: 0px 3px 0px #999999;
cursor: pointer;
}
.button:hover {
background: #a1a1a1
}
.button:active {
box-shadow: 0px 0px 0px #999999;
}
Click me
So pretty straight forward. A button, a hover effect, and an active effect. However, what I would actually like is the effect of pushing the button. Now the box-shadow just disappears, but the button itself doesn't go "down" so to speak...
It's pretty easy with just a button, but I need this for a -button. Can it be done ? :)
You can add position: relative to the button and add top: -1px on :active for 1px top offset.
.button {
background: #aaaaaa;
padding: 20px 30px;
font-weight: bold;
color: #ffffff;
text-transform: uppercase;
border-radius: 15px;
box-shadow: 0px 3px 0px #999999;
cursor: pointer;
position: relative;
}
.button:hover {
background: #a1a1a1
}
.button:active {
top: -1px;
}
Click me
You can use the transform scale property. This will make an illusion that the button is clicked since it becomes smaller on active.
.button {
transition: all 1s;
}
.button:active {
transform:scale(0.8,0.8);
}
https://www.w3schools.com/cssref/playit.asp?filename=playcss_transform_scale
You can do that manually like that :
.button {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
.button:hover {background-color: #3e8e41}
.button:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_buttons_animate3
Or you could also use the material design through the materialize package:
https://www.w3schools.com/w3css/w3css_material.asp
And this is an example for buttons :
<a class="waves-effect waves-light btn">button</a>
http://materializecss.com/buttons.html
I can't seem to get the bottom of the buttons to show, I tried increasing padding on the span, setting it to display: block, and increasing the height of the A and SPAN elements to no avail.
JS Fiddle Link: http://jsfiddle.net/7tcrz38r/
CSS:
/* Menu */
div#menu{
float: right;
margin-top: [[setting:menuMarginTop]];
}
div#menu ul{
list-style: none;
margin: 0;
padding: 0;
}
div#menu>ul>li{
float: left;
padding: 0;
}
div#menu li.has-sub>ul{
background: #FFFFFF;
border-top: 4px solid [[setting:color1]] !important;
box-sizing: border-box;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
height: 110px;
display: none;
height: auto;
margin: -12px 0 0 16px;
padding: 0px;
position: absolute;
width: 170px;
z-index: 2000;
}
div#menu li.has-sub>ul>li{
border-bottom: 1px solid #EEEEEE;
border-left: 1px solid #DDDDDD;
border-right: 1px solid #DDDDDD;
padding: 10px;
}
div#menu li.has-sub>ul>li>a{
color: #949494;
font-size: 12px !important;
text-decoration: none;
}
div#menu li.has-sub>ul>li>a:hover{
color: [[setting:color1]];
}
div#menu li:hover ul {
display: block;
}
div#menu>ul>li>a {
color: #868787;
display: inline-block;
font-size: 18px !important;
font-weight: lighter;
letter-spacing: 1px !important;
margin: 17px 15px !important;
outline: none;
position: relative;
text-decoration: none;
text-shadow: 0 0 1px rgba(255,255,255,0.3);
}
/*div#menu>ul>li>a.active{
color: [[setting:color1]] !important;
background-color: #c3d9e3;
border: 2px solid #abd1eb;
border-radius: 5px;
}*/
div#menu>ul>li:last-child>a{
margin: 17px 0 17px 15px !important
}
div#menu>ul>li:last-child>a{
margin-right: 0 !important;
}
div#menu>ul>li>a:hover,
div#menu>ul>li>a:focus {
outline: none;
}
div#menu>ul>li>a{
overflow: hidden;
padding: 0 !important;
height: 1.3em !important;
}
div#menu>ul>li>a>span {
display: block;
position: relative;
border: 2px solid #eef3f5;
/*-webkit-transition: -webkit-transform 0.3s;
-moz-transition: -moz-transform 0.3s;
transition: transform 0.3s;*/
}
div#menu>ul>li>a>span::before {
position: absolute;
top: 100%;
content: attr(data-hover);
/*-webkit-transform: translate3d(0,0,0);
-moz-transform: translate3d(0,0,0);
transform: translate3d(0,0,0);*/
}
div#menu>ul>li>a:hover span,
div#menu>ul>li>a:focus span {
/* background-color: #c3d9e3;
border: 1px solid #abd1eb;
border-radius: 25%;*/
background-color: #c3d9e3;
border: 2px solid #abd1eb;
border-radius: 5px;
/*-webkit-transform: translateY(-100%);
-moz-transform: translateY(-100%);
transform: translateY(-100%);
color: [[setting:color1]];*/
}
/*
div#menu>ul>li>a.menuactive{
color: [[setting:color1]];
}*/
HTML:
<div id="menu">
<ul><li >
<span data-hover="Home">Home</span></li><li >
<span data-hover="Classes">Classes</span></li><li >
<span data-hover="Pricing">Pricing</span></li><li >
<span data-hover="About Us">About Us</span></li><li >
<span data-hover="Log In">Log In</span></li> </ul>
</div>
You are setting a fixed height(1.3em !important;) for A which is causing this issue.
Please check this updated working fiddle:http://jsfiddle.net/7tcrz38r/2/
you have this declaration:
div#menu>ul>li>a {
overflow: hidden;
padding: 0 !important;
height: 1.3em !important;
}
which, by the way, is repeated since it's declared some lines above
div#menu>ul>li>a {
color: #868787;
display: inline-block;
font-size: 18px !important;
font-weight: lighter;
letter-spacing: 1px !important;
margin: 17px 15px !important;
outline: none;
position: relative;
text-decoration: none;
text-shadow: 0 0 1px rgba(255, 255, 255, 0.3);
}
Anyways, just remove that overflow:hidden property. However, you'll have the menu items showing twice because of that data-hover span you have. I don't know why are you using that, so consider if you need it or not. Of course, you can simply remove that "height: 1.3em !important;" as well, but I assume it's better to have a height than an overflow. anyways, it's a a decision you'll have to ponder
I'd like to crop this image and set it as a background-image of the anchor tag which is a circle, how can I do that?
a {
display: inline-block;
width: 100px;
height: 100px;
color: #000;
border: 1px solid black;
border-radius: 50%;
box-shadow: 0 0 4px black;
text-align: center;
line-height: 100px;
text-decoration: none;
}
a:hover {
background: #ffff99;
border-color: white;
}
Home
About
Services
Products
Contact
You can use background-position to position the background and background-size (no support in IE8 though) to scale it:
a {
background-image: url("http://www.kruger-us-targets.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/1/3/1300_p.png");
background-position: center;
background-size: 190%;
display: inline-block;
width: 100px;
height: 100px;
color: #fff;
border: 1px solid black;
border-radius: 50%;
box-shadow: 0 0 4px black;
text-align: center;
line-height: 100px;
text-decoration: none;
}
a:hover {
color: #000;
background: #ffff99;
border-color: white;
}
Home
About
Services
Products
Contact
What I am trying to accomplish on :hover.
.nav li {
margin: 12px 0 0 20px; padding: 0;
color: #000; font-weight: 700;
display: inline-block;
}
.nav li+li:hover {
background: #2f3343;
padding: 5px 10px 5px 10px;
margin: 0 -2px 0 20px;
border-radius: 2px;
font-weight: 700;
border: none;
}
.nav .triangle {
width: 0px;
height: 0px;
border-style: solid;
border-width: 10px 12.5px 0 12.5px;
border-color: #000000 transparent transparent transparent;
}
I would like to put the triangle in the :hover but it's completely messed up. Do I need to set a specific height and add a position?
Try this
i create a new
.nav li {
margin: 12px 0 0 20px; padding: 0;
color: #000; font-weight: 700;
display: inline-block;
padding: 5px 10px 5px 10px;
position:relative;
border-radius: 2px;
}
.nav li:hover {
background: #2f3343;
border: none;
}
.nav li:hover:after {
content:"";
border-style: solid;
position: absolute;
left: 50%;
bottom: -10px;
margin-left:-10px;
border-width: 10px 12.5px 0 12.5px;
border-color: #000000 transparent transparent transparent;
}
Demo
Try the following css:
.arrow {
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #000;
margin-left: 15px;
display: none;
}
button:hover + .arrow {
display: block;
}
I have made a JSFiddle similar to this. Have a look and provide your comments.