Howto make an HTML box with shadow and pressable - html

I would like to make an HTML widget like this one:
https://jsfiddle.net/api/mdn/
.simple {
box-shadow: 5px 5px 5px rgba(0,0,0,0.7);
}
But I would like it to be pressable so that it flattens for 1 second and redirects to a different URL.
Edit:
I tried the following:
button {
width: 150px;
font-size: 1.1rem;
line-height: 2;
border-radius: 10px;
border: none;
background-image: linear-gradient(to bottom right, #777, #ddd);
box-shadow: 5px 5px 5px rgba(0,0,0,0.7);
}
button:focus, button:hover {
background-image: linear-gradient(to bottom right, #888, #eee);
}
button:active {
box-shadow: inset 2px 2px 1px black,
inset 2px 3px 5px rgba(0,0,0,0.3),
inset -2px -3px 5px rgba(255,255,255,0.5);
}
<button>Press me!</button>
https://jsfiddle.net/z7a0v8uv/
But I don't know how to translate the content of the button to make it look like it's being pressed down.

I found an answer here:
https://www.w3schools.com/howto/howto_css_animate_buttons.asp
I was looking for:
translateX(...) translateY(...)
As we can see in this working example:
https://jsfiddle.net/z7a0v8uv/1/
Now I just need to integrate this with the right style.
Edit:
Here is the complete CSS code:
button {
width: 100%;
border: none;
box-shadow: 5px 5px 5px rgba(0,0,0,0.7);
}
button:focus, button:hover {
background-image: linear-gradient(to bottom right, #888, #eee);
}
button:active {
box-shadow: 2px 2px 2px rgba(0,0,0,0.7);
transform: translateY(3px) translateX(3px);
}

Related

Button text won't be displayed properly in browsers other than Firefox

So I'm studying javascript and I had to do Pokemon-themed app. My goal was to create a Pokeball shaped button and it looked actually pretty decent, but then I deploy it and my friends start notifying me that the button looks awful. I tested it on Chrome, Edge and Brave and it looks bad in all of them, Firefox being the only exception.
So this is my CSS code (I'm using styled components):
const PokeButton = styled.button`
border-radius: 100%;
border: 3px solid black;
width: 3rem;
height: 3rem;
padding-inline: 0 0;
outline: 2px solid black;
border: 2px solid white;
text-shadow: 2px 0 0 #000, -2px 0 0 #000,
0 2px 0 #000, 0 -2px 0 #000, 2px 2px 0 #000,
-2px -2px 0 #000, -2px 2px 0 #000, 2px -2px 0 #000;
-webkit-text-fill-color: white;
background: linear-gradient(180deg, rgb(239, 21, 21) 50%, white 50%);
&:hover {
transition: .5s;
transform: rotate(15deg);
width: 3.6rem;
height: 3.6rem;
}
&:active {
transition: .2s;
transform: rotate(-45deg);
width: 2.6rem;
height: 2.6rem;
padding-inline: 0 1rem;
}
transition: .2s;
margin-left: 1rem;
overflow: hidden;
cursor: pointer;
`;
And here is my HTML for the Button:
<PokeButton type="submit" >―⬤—</PokeButton>
The problem I have is that on Firefox, the overflow is hidden properly, but in the rest of browsers, the first em-dash and the circle are in the upper half of the ball -and not centered- while the second dash is in the lower half (except on hover, where it looks the way it should). On Firefox, they're all in the middle and the circle is centered.
What can I do to fix this?

Styling a <select> dropdown

I am trying to style a <select> dropdown to look something similar to this. As in I want the grey background on page load and then the blue-ish color when it is active.
Here is what I have gotten so far. The main thing I'm trying to figure out is the colored block with the arrow to the right of the element.
select {
background: url(media/icons/down_arrow.png) no-repeat 90% ;
background-size: 15px 10px;
height: 30px;
overflow: hidden;
width: 100px;
font-size: 14px;
padding: 5px 10px;
border: 2px solid #777;
border-radius: 10px;
background-color: #EEE;
color: #000;
-webkit-appearance: none;
box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.5);
}
select:active, select:focus, select:hover {
border: 2px solid #55E;
}
<select>
<option>1000</option>
<option>2000</option>
<option>3000</option>
<option>4000</option>
<option>5000</option>
</select>
P.S. the png is just a down arrow that is 15px x 10px
You can consider gradient coloration
select {
background:
/*to replace the arrow*/
linear-gradient(to bottom right,#fff 48%,transparent 50%) right 7px top 50%/8px 10px,
linear-gradient(to bottom left,#fff 48%,transparent 50%) right 15px top 50%/8px 10px,
/* remove the above gradient and uncomment the below to use your arrow
url(media/icons/down_arrow.png) right 5px top 50%/15px 10px,
*/
var(--c,linear-gradient(#939393,#595959)) right/30px 100%,
linear-gradient(#fffff9,#cfced5);
background-repeat:no-repeat;
font-size: 18px;
padding:10px 40px 10px 10px;
border: 2px solid #777;
border-radius: 10px;
color: #000;
-webkit-appearance: none;
box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.5);
}
select:active, select:focus, select:hover {
border: 2px solid #55E;
/*Used a variable to avoid repeating all the background definition*/
--c:linear-gradient(#6c81b7,#264091);
}
<select>
<option>1000</option>
<option>2000</option>
<option>3000</option>
<option>4000</option>
<option>5000</option>
</select>

How to give shadow in a button like this?

In this button a shadow appearing and it looks like another button border there. I tried to use box-shadow property but I failed.
I used this CSS
a {
padding: 10px 40px;
border-radius: 30px;
font-size: 18px;
color: #fff;
border: 1px solid #fff;
box-shadow: 5px 5px 0px #2CBFBB;
}
Can anyone please help me?
You can achieve this effect with filter: drop-shadow and a transparent background:
body {
background: #76D7C4;
}
button {
text-transform: uppercase;
padding: 10px 20px;
color: white;
cursor: pointer;
background: transparent; /* no background! */
border: 1px solid white;
border-radius: 100px;
filter: drop-shadow(5px 5px 1px rgba(0, 0, 0, 0.25));
}
<button>Learn More</button>
Based on chazsolo's answer. It's possible to get shadow on button without shadow on text using absolutely positioned pseudoelement and CSS property inheritance:
body {
background: #76d7c4;
}
button {
text-transform: uppercase;
padding: 10px 20px;
color: white;
cursor: pointer;
background: transparent; /* no background! */
border: 1px solid white;
border-radius: 100px;
position: relative; /* new */
}
button:after {
content: "";
position: absolute;
/* Making pseudoelement the same size as container */
left: 0;
right: 0;
top: 0;
bottom: 0;
/* Inheriting border properties */
border-radius: inherit;
border: inherit;
/* Applying filter with shadow */
filter: drop-shadow(5px 5px 1px rgba(0, 0, 0, 0.25));
}
<button>Learn More</button>
You can also do it by combining box-shadow: ... and box-shadow: inset .... Just adjust the box-shadow so it fits your needs.
Example
body {
background: #32DBD7;
}
button {
background: transparent;
color: #fff;
border: 3px solid #fff;
border-radius: 35px;
padding: 10px 40px;
font-size: 34px;
box-shadow: 3px 3px 4px rgba(0, 0, 0, .25), inset 3px 3px 4px rgba(0, 0, 0, .25);
-moz-box-shadow: 3px 3px 4px rgba(0, 0, 0, .25), inset 3px 3px 4px rgba(0, 0, 0, .25);
-webkit-box-shadow: 3px 3px 4px rgba(0, 0, 0, .25), inset 3px 3px 4px rgba(0, 0, 0, .25);
}
<button>Learn More</button>
.test { margin-top: 2em; }
a {
padding: 10px 40px;
border-radius: 30px;
font-size: 18px;
color: #fff;
border: 1px solid #fff;
box-shadow: 5px 5px 0 darkgray;
text-decoration: none;
}
body {
background-color: #2CBFBB;
}
<div class="test">
Learn More
</div>

How do I get the box shadow to show up on my content-bg?

I'm working on a site called http://ccrccmo.com and I can't get the box-shadow to show up on the content-bg with css.
nav{
background:url(images/nav-bg2.png);
height:74px;
box-shadow: 0px 3px 5px #222;
}
#content-bg{
background:white;
margin-top:0px;
z-index:-1000;
}
you are missing
box-shadow: inset 0 3px 10px #000;
box-shadow: initial;
try
#content-bg {
background: white;
margin-top: 0px;
box-shadow: inset 0 3px 10px #000;
box-shadow: initial;
}

jQuery click issue with a span styled to look like a button

Context
I've this buttons:
I detect when the user is clicking with jQuery .click().
But it works only if the user clicks on the text ("imdb" / "rottenTomatoes").
If the user clicks on the blue of button, jQuery detects nothing.
You can try on http://promobluray.fr.
Questions
What is the problem?
How to get this to work like a button?
Code
html:
<span class="rating">
<span class="rating-btn imdb active">imdb</span>
<span class="rating-btn rt">rottenTomatoes</span>
</span>​
css:
.rating {
padding: 14px;
}
.rating-btn {
display: inline-block;
margin-top: 24px;
padding: 4px;
position: relative;
font-family: 'Open Sans',sans-serif;
font-size: 12px;
text-decoration: none;
color: white;
cursor: pointer;
background-image: -o-linear-gradient(bottom,#2CA0CA 0,#08C 100%);
background-image: -moz-linear-gradient(bottom,#2CA0CA 0,#08C 100%);
background-image: -webkit-linear-gradient(bottom,#2CA0CA 0,#08C 100%);
background-image: -ms-linear-gradient(bottom,#2CA0CA 0,#08C 100%);
background-image: linear-gradient(bottom,#2CA0CA 0,#08C 100%);
-webkit-box-shadow: inset 0 1px 0 #7fd2f1,0px 6px 0 #156785;
-moz-box-shadow: inset 0 1px 0 #7fd2f1,0px 6px 0 #156785;
box-shadow: inset 0 1px 0 #7fd2f1,0px 6px 0 #156785;
border-radius: 5px;
}
.rating-btn::before {
background-color: #072239;
content: "";
display: block;
position: absolute;
width: 100%;
height: 100%;
padding-left: 2px;
padding-right: 2px;
padding-bottom: 4px;
left: -2px;
top: 5px;
z-index: -1;
border-radius: 6px;
-webkit-box-shadow: 0 1px 0 #fff;
-moz-box-shadow: 0 1px 0 #fff;
box-shadow: 0 1px 0 #fff;
}
.active {
background: #2CA0CA;
-webkit-box-shadow: inset 0 1px 0 #7fd2f1,inset 0 -1px 0 #156785;
-moz-box-shadow: inset 0 1px 0 #7fd2f1,inset 0 -1px 0 #156785;
box-shadow: inset 0 1px 0 #7fd2f1,inset 0 -1px 0 #156785;
top: 7px;
cursor: default;
}
.imdb {
margin-right: 5px;
}
jquery:
$('.rating-btn').click(function() { ... });
​
You could try to increase the padding of the button so that the <span> matches the dimension of the image, but i think that the best solution is to change your markup and actually use <button>
It's seems to work in the latest versions of FF and IE, but not Chrome, Opera and Safari(win). I would suggest adding display:block; to .rating-btn styles to see what that does.
Alternatively, actually use buttons and style those how you want.
Use parent to attach handler
$('.rating:has(.rating-btn)').click(function() { ... });