CSS button use of .hover for different buttons - css

This is the top part:
button {
background-color: gray;
color: #fff;
border: none;
border-radius: 3px;
padding: 3px 10px;
cursor: pointer;
min-width: 1%;
min-height: 30px;
margin: 1px 0;
font-size: 16;
font-weight: bold;
box-shadow: 4px 4px 2px 0px #333333;
}
.blue-btn {
background-color: #337AB7;
}
.green-btn {
background-color: #008000;
}
.red-btn {
background-color: #FF0000;
}
Here comes my problem…..
.button:hover {
background-color: #3e8e41;
box-shadow: 0px 0px 0px 0px;
}
This one only work if the class is button (it does not work for blue/green/red buttons)
So I tried this instead
.button:hover, blue-btn:hover, green-btn:hover, red-btn:hover {
background-color: #3e8e41;
box-shadow: 0px 0px 0px 0px;
}
Still only works for button class
So I tried this one
.blue-btn:hover {
background-color: #3e8e41;
box-shadow: 0px 0px 0px 0px;
}
.green-btn:hover {
background-color: #3e8e41;
box-shadow: 0px 0px 0px 0px;
}
.red-btn:hover {
background-color: #3e8e41;
box-shadow: 0px 0px 0px 0px;
}
That worked – but it seem to me its a bit stupid to write the same bit again and again and again……
Anyone got a tip?

Use button:hover instead of .button:hover .

First off, you're confusing element names with classes. A button is an actual element (<button></button>) and .button is a class you've created.
I don't know if what you have is a button with the class of button because you didn't post any HTML but know that isn't good practice, it's redundant and confusing.
Give all the elements that you want to have a hover effect an encompassing class like .hover and the specific class of .blue or .red as applicable to the color you want.
.hover {
background: #3e8e41;
box-shadow: 0px 0px 0px 0px;
}
.blue {
background: #337AB7;
}
.green {
background: #008000;
}
.red {
background: #FF0000;
}

Related

How do I change background for the thumb with styled components?

I'm trying to change the background color for the thumb with styled-components for react, but I do not know how, cant seem to get it. My styled-components look like this:
const InputVolume = styled.input`
::-webkit-slider-runnable-track {
width: 100%;
height: 4px;
cursor: pointer;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
background-color: #FFFFFF;
border-radius: 25px;
border: 0px solid #000101;
};
&:focus::-webkit-slider-runnable-track {
background: #D78E91;
};
::-webkit-slider-thumb {
background-color: #FFFFFF;
}
`;
Word of warning: the MDN docs recommend against using this in production.
It looks like you're just missing setting some appearance: none properties and then adding a few more to specify things like height and width. Here is a working example of the snippet below.
Also, it looks like you have some typos in your styles. You've got a border set to 0px, same with your box shadow, and a border radius that only needs to be 2px, not 25px (based on the height and what I'm assuming you're trying to do with it).
const InputVolume = styled.input`
appearance: none;
cursor: pointer;
::-webkit-slider-runnable-track {
height: 4px;
width: 100%;
cursor: pointer;
pointer-events: none;
box-shadow: 0px 0px 0px #000000, 0px 0px 0px #0d0d0d;
background-color: #fff;
border-radius: 2px;
border: 1px solid #000101;
}
&:focus {
outline: none;
}
&:focus::-webkit-slider-runnable-track {
background: #d78e91;
}
&::-webkit-slider-thumb {
height: 16px;
width: 16px;
appearance: none;
background: #fff;
border-radius: 8px;
margin-top: -6px;
border: 1px solid #777;
}
`;

How to get rid of inbuilt CSS that gets appended on hover?

I am using Safari browser and I have buttons like this -
On hover these look like as below -
I haven't added any css from my side but on inspect element I got this-
button:hover {
box-shadow: 0px 0px 1px #b2b2b2;
border-left-color: #575757;
border-right-color: #575757;
}
I want to make it look like same on hover or not hover. So I tried setting css as-
button:hover {
box-shadow: none;
border-left-color: none;
border-right-color: none;
}
But it's not working.
You can use this code
button {
box-shadow: 0px 0px 1px #b2b2b2;
background-color: #ffffff;
border: 1px solid #575757;;
outline: none;
padding: 15px 30px;
text-decoration: none;
border-radius: 15px;
font-size: 25px;
font-weight: 600;
color: #333333;
}
button:hover {
box-shadow: 0px 0px 1px #b2b2b2;
background-color: blue;
border: 1px solid #575757;;
outline: none;
padding: 15px 30px;
text-decoration: none;
color: white;
}
<button type="button">Prev</button>
<button type="button">1</button>
<button type="button">2</button>
<button type="button">3</button>
<button type="button">Next</button>

input range - height 0 works only in firefox

I have a custom style input range and I want to have height 0 to support my style -> the idea is to not have any in built style so I can make my slider appear according to a separate span element styles included on top, so for the span element to be visible, my input range custom styles should not be visible at all.
While my idea worked like a charm it is preventing click from working on safari and chrome - on firefox the click still works properly, with height 0.
Is there a way to tweak my input range style such that I can achieve this? Please find my input range styles below:
Css
input[type=range] {
-webkit-appearance: none;
width: 100%;
margin: 6.8px 0;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 0px;
cursor: pointer;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
box-shadow: transparent;
background: rgba(0, 0, 0, 0);
border-radius: 0px;
border: 0px solid rgba(0, 0, 0, 0);
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 0px solid #000000;
height: 20px;
width: 20px;
border-radius: 20px;
background: #ffffff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -8.8px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
// background: rgba(13, 13, 13, 0);
background: rgba(0, 0, 0, 0);
}
Html
<input id="scrollbar" class="scrollbar" type="range" min=1 max=24 step="0.01" />
okay I solved the problem! We can provide background transparent. That made the slider clickable!
I found an excellent article on this topic.
input[type=range] {
-webkit-appearance: none;
width: 100%;
margin: 6.8px 0;
background: transparent;
}
input[type=range]:focus {
outline: none;
}
input[type=range]::-webkit-slider-runnable-track {
width: 100%;
height: 5px;
cursor: pointer;
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
box-shadow: transparent;
border-radius: 0px;
background: transparent;
border-color: transparent;
color: transparent;
}
input[type=range]::-webkit-slider-thumb {
box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
border: 0px solid #000000;
height: 20px;
width: 20px;
border-radius: 20px;
background: #ffffff;
cursor: pointer;
-webkit-appearance: none;
margin-top: -8.8px;
}
input[type=range]:focus::-webkit-slider-runnable-track {
background: transparent;
}
<input id="scrubber" class="scrollbar" type="range" min=1 max=24 step="0.01" />
** Please run on chrome and safari to test:D
I hope this post helps someone.

box-shadow on <button> is cut off on Safari ONLY

I'm trying to achieve a 'press' button effect with a <button> and a <span> but for some reason the shadow is getting cut off on Safari ONLY.
I'm using two tags here because that's a limitation of the website i'm editing, I can't change the markup.
It's simple as this, HTML:
<button><span>A simple fucking button</span></button>
CSS:
button {
-webkit-appearance: none;
border: none;
background: none;
padding: 0;
margin: 0;
}
button span {
text-transform: uppercase;
font-weight: bold;
border: 3px solid black;
padding: 10px 35px;
border-radius: 2em;
display: block;
background-color: #fff;
box-shadow: 0px 4px 0px -2px #bfbfbf,
0px 5px 0px 0px black;
}
button:active,
button:hover {
color: inherit;
}
button:hover {
span {
transform: translate(0px, 5px);
box-shadow: 0px 0px 0px 0px;
}
}
codepen.io example:
https://codepen.io/marlonmarcello/pen/dVBKpd
If you are open to dropping the span, then the button and styles can be adjusted to achieve the desired effect:
https://codepen.io/enquiren/pen/qMzLrd
button {
-webkit-appearance: none;
border: none;
background: none;
padding: 0;
margin: 0;
cursor: pointer;
&.pushable {
text-transform: uppercase;
font-weight: bold;
border: 3px solid black;
padding: 10px 35px;
border-radius: 2em;
display: block;
background-color: #fff;
box-shadow: 0px 4px 0px -2px #bfbfbf,
0px 5px 0px 0px black;
&:hover {
transform: translate(0px, 5px);
box-shadow: 0px 0px 0px 0px;
}
}
}
<button class="pushable">A simple button</button>

Button push down effect on <a> button

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

Resources