So I have 2 buttons inside a flexbox with a transition on hover that makes the button shrink in padding and darken. The only problem is that when I hover over one button and the transition performs, it moves the other button as well. How do I fix this.
TL;DR I don't want the other button to move when I :hover.
.buttons {
margin-top: 3rem;
display: flex;
justify-content: space-evenly;
}
.buttons__change {
/*👉left: 25%;
position: relative;👈*/
font-family: "Roboto", sans-serif;
padding: 12px 52px;
background: white;
border: 2px solid rgb(201, 83, 5);
color: rgb(201, 83, 5);
font-size: 1.5rem;
text-decoration: none;
-webkit-appearance: none;
}
.buttons__pay {
/*👉left: 45%;
position: relative;👈*/
font-family: "Roboto", sans-serif;
padding: 12px 52px;
background: rgb(201, 83, 5);
border: 2px solid rgba(201, 83, 5);
color: white;
font-size: 1.5rem;
text-decoration: none;
-webkit-appearance: none;
cursor: pointer;
}
.buttons__change:hover,
.buttons__change:focus,
.buttons__pay:hover,
.buttons__pay:focus {
background-color: rgb(209, 179, 124);
opacity: .7;
color: gray;
cursor: pointer;
padding: 8px 28px;
-webkit-transition: .45s .08s;
-o-transition: .45s .08s;
transition: .45s .08s;
}
<div class="buttons">
<a class="buttons__change" href="services.html">Change Selection</a>
<button class="buttons__pay" type="submit">Secure Checkout</button>
</div>
You changed the padding, so elements that flow around it will adjust to the new spacing they need to flow around. The easiest solution is to account for the missing padding with an equal-sized margin.
The HTML box drawing has padding inside the box and margin outside the box, so you get the desired effect.
To be explicit, I set a zero margin on each button (which you could abstract btw—there's no need to duplicate any entries, that just makes them harder to update) and then added the pixels removed from the padding on :hover.
.buttons {
margin-top: 3rem;
display: flex;
justify-content: space-evenly;
}
.buttons__change {
/*👉left: 25%;
position: relative;👈*/
font-family: "Roboto", sans-serif;
padding: 12px 52px;
margin: 0;
background: white;
border: 2px solid rgb(201, 83, 5);
color: rgb(201, 83, 5);
font-size: 1.5rem;
text-decoration: none;
-webkit-appearance: none;
}
.buttons__pay {
/*👉left: 45%;
position: relative;👈*/
font-family: "Roboto", sans-serif;
padding: 12px 52px;
margin: 0;
background: rgb(201, 83, 5);
border: 2px solid rgba(201, 83, 5);
color: white;
font-size: 1.5rem;
text-decoration: none;
-webkit-appearance: none;
cursor: pointer;
}
.buttons__change:hover,
.buttons__change:focus,
.buttons__pay:hover,
.buttons__pay:focus {
background-color: rgba(209, 179, 124);
opacity: .7;
color: gray;
cursor: pointer;
padding: 8px 28px;
margin: 4px 24px;
-webkit-transition: .45s .08s;
-o-transition: .45s .08s;
transition: .45s .08s;
}
<div class="buttons">
<a class="buttons__change" href="services.html">Change Selection</a>
<button class="buttons__pay" type="submit">Secure Checkout</button>
</div>
I didn't want to change anything else about your code, but I do recommend the hovered buttons have at least as high a contrast as the buttons do before hovering. Legibility shouldn't decrease when your attention is focused on the button. (Try background-color: rgba(209, 179, 124, 0.7); color: black; for example. This ensures the text color isn't rendered 30% transparent (from your opacity: .7;) while the background color is.)
Related
I am attempting to place two buttons side by side, one of which has a border, and both of which are the same height. But even though I am using box-sizing: border-box, the border is still being added to the height.
Here are the links:
.btn {
padding: 10px;
text-align: center;
line-height: 1.15;
border: 0;
cursor: pointer;
box-sizing: border-box;
}
.dib {
display: inline-block !important;
}
.btn {
background-color: initial;
text-align: initial;
letter-spacing: initial;
-webkit-transition: initial;
transition: initial;
-webkit-box-shadow: initial;
box-shadow: initial;
height: initial;
border-radius: initial;
vertical-align: initial;
text-transform: initial;
}
.btn,
.btn-large,
.btn-small {
text-decoration: none;
color: #fff;
background-color: #26a69a;
text-align: center;
letter-spacing: .5px;
-webkit-transition: background-color .2s ease-out;
transition: background-color .2s ease-out;
cursor: pointer;
}
.btn,
.btn-large,
.btn-small,
.btn-flat {
border: none;
border-radius: 2px;
display: inline-block;
height: 36px;
line-height: 36px;
padding: 0 16px;
text-transform: uppercase;
vertical-align: middle;
-webkit-tap-highlight-color: transparent;
}
.btn-ghost-secondary {
background-color: transparent;
border: 2px solid #261a94;
}
<a class="btn btn-ghost-secondary dib">Delete Entity</a>
<a class="btn btn-secondary dib">Edit Entity</a>
My understanding of border-box leads me to believe that the height of the btn-ghost-secondary button should be unaffected by the 2px border, and yet its height is exactly 4px more than that of its sibling.
I even tried removing all style other than display, padding, box-sizing and borders (you can see the difference in the buttons on the left hand side):
As you can see on the screenshot below, my pink button is not fully responsive: below a certain width it gets cut instead of resizing to remain within the viewport width.
What is the issue?
Many thanks
.btn {
background-color: #ff00bf;
border: 0 none;
border-radius: 25px;
box-shadow: 0 11px 22px rgba(34, 34, 34, 0.2);
color: #fff;
display: inline-block;
font-size: 1rem;
letter-spacing: 0.025em;
padding: 1.1em 2.28em 1em;
text-decoration: none;
transition: all 0.3s ease-out 0s;
}
.btn {
-moz-user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: normal;
line-height: 1.42857;
margin-bottom: 0;
padding: 6px 12px;
text-align: center;
touch-action: manipulation;
vertical-align: middle;
white-space: nowrap;
}
The white-space: nowrap makes line-breaking impossible. Just remove it. Also I would set the max-width to 100%.
.btn {
background-color: #ff00bf;
border: 0 none;
border-radius: 25px;
box-shadow: 0 11px 22px rgba(34, 34, 34, 0.2);
color: #fff;
display: inline-block;
font-size: 1rem;
letter-spacing: 0.025em;
padding: 1.1em 2.28em 1em;
text-decoration: none;
transition: all 0.3s ease-out 0s;
}
.btn {
-moz-user-select: none;
background-image: none;
border: 1px solid transparent;
border-radius: 4px;
cursor: pointer;
display: inline-block;
font-size: 14px;
font-weight: normal;
line-height: 1.42857;
margin-bottom: 0;
padding: 6px 12px;
text-align: center;
touch-action: manipulation;
vertical-align: middle;
max-width: 100%;
}
I would like my button to have a background/font-color transition when I hover it, but not when I am clicking it (active).
Currently I have the transition effect on both hover and active.
I tried adding transition: 0s ease-out; on either :active or :hover but I didn't get the expected result.
What is correct, cleanest and simplest way to do this (by using css) ?
button {
position: absolute;
width: 80px;
height: 28px;
font-size: 13px;
font-weight: 700;
line-height: 28px;
color: #6cb4d5;
font-family: 'Lato', sans-serif;
padding: 0;
border: 0;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
border-left: 1px solid #CCC;
background-color: #fff;
transition: 0.3s ease-out;
}
button:hover {
color: #f7f7f7;
background-color: #6cb4d5;
outline: 0;
}
button:active {
color: #f7f7f7;
background-color: #398cb2;
outline: 0;
}
<button type="submit" name="sub-avatar-url" id="sub-avatar-url"> UPLOAD</button>
Thanks a lot.
Try this https://jsfiddle.net/2Lzo9vfc/93/
button {
position: absolute;
width: 80px;
height: 28px;
font-size: 13px;
font-weight: 700;
line-height: 28px;
color: #6cb4d5;
font-family: 'Lato', sans-serif;
padding: 0;
border: 0;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
border-left: 1px solid #CCC;
background-color: #fff;
transition: all 0.3s ease-out;
}
button:hover {
color: #f7f7f7;
background-color: #6cb4d5;
outline: 0;
}
button:active {
color: red;
background-color: blue;
outline: 0;
transition: none;
}
If you want the button to go back to it's original colors on button:active, then adding in the original values to the :active block will correct this.
However, if you want to display the colors you have while hovering over the button while active, simply removing the :active block will give that effect.
Both are here next to each other. Hopefully this is what you wanted. :)
https://jsfiddle.net/2Lzo9vfc/94/
button {
position: absolute;
width: 80px;
height: 28px;
font-size: 13px;
font-weight: 700;
line-height: 28px;
color: #6cb4d5;
font-family: 'Lato', sans-serif;
padding: 0;
border: 0;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
border-left: 1px solid #CCC;
background-color: #fff;
transition: all 0.3s ease-out;
}
button:hover {
color: #f7f7f7;
background-color: #6cb4d5;
outline: 0;
}
#sub-avatar-url2:hover {
color: #f7f7f7;
background-color: #6cb4d5;
outline: 0;
}
#sub-avatar-url2:active {
background-color: #fff;
color: #6cb4d5;
outline: 0;
transition: none;
}
<button type="submit" name="sub-avatar-url" id="sub-avatar-url"> UPLOAD</button> <br><br>
<button type="submit" name="sub-avatar-url2" id="sub-avatar-url2">   UPLOAD</button>
This May Help you-
button {
position: absolute;
width: 80px;
height: 28px;
font-size: 13px;
font-weight: 700;
line-height: 28px;
color: #6cb4d5;
font-family: 'Lato', sans-serif;
padding: 0;
border: 0;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
border-left: 1px solid #CCC;
background-color: #fff;
transition: 0.3s ease-in;outline: 0;
}
button:hover {
color: #f7f7f7;
background-color: #6cb4d5;
outline: 0;
}
button:active {
color: #f7f7f7;
background-color: #398cb2;
outline: 0;transition:all 0ms ease-out
}
button:focus{transition:all 0ms ease-out}
You could try applying the transition: 0s; to the active statement - however, you also need to add in the :focus event to the declaration chain to prevent the button transitioning when you release the click.
You can see the fiddle here:
http://jsfiddle.net/eks8Lc5c/
I have a problem in my button width. my form is able to switch language. For some language the content of the button is longer then the button width, How can I adjust the button width proprety to the text lenght ?
Here is my CSS :
html .formRowSubmit input[type="submit"] {
width: 26%;
margin: 5px 0% 5px ;
margin-bottom: 10px;
height: 25px;
border-radius: 3px;
outline: 0;
-moz-outline-style: none;
background: #CAD722;
border: none;
color: white;
font-size: 10px;
font-weight: 150;
cursor: pointer;
transition: box-shadow .4s ease;
}
You should try setting a min-width instead of a width, this will let the button expand if need be. Once you do this you should also set some horizontal padding so the text isnt butted up to the end like so:
input[type="submit"] {
min-width: 26%;
padding: 5px 15px;
}
http://jsfiddle.net/jqjxd0xt/
Display the button as an inline-block (and delete the width)
html .formRowSubmit input[type="submit"] {
/*width: 26%;*/
display: inline-block;
margin: 5px 0% 5px ;
margin-bottom: 10px;
height: 25px;
border-radius: 3px;
outline: 0;
-moz-outline-style: none;
background: #CAD722;
border: none;
color: white;
font-size: 10px;
font-weight: 150;
cursor: pointer;
transition: box-shadow .4s ease;
}
You might want to add some padding if the text is to close to the border.
Try like this: demo
CSS:
.formRowSubmit input[type="submit"] {
width: auto;
margin: 5px 0% 5px;
margin-bottom: 10px;
height: 25px;
border-radius: 3px;
outline: 0;
-moz-outline-style: none;
background: #CAD722;
border: none;
color: white;
font-size: 10px;
font-weight: 150;
cursor: pointer;
transition: box-shadow .4s ease;
}
HTML:
<div class="formRowSubmit">
<input type="submit" value="Submit loooong llloooonnnng text">
</div>
i'm making a button and I want to achieve an insteresting effect that you can see here.
The problem is that when on hover I put to the text rgba(0,0,0,0.0); all the button turns white, even the text.
Here's my code so far:
.button{
height: 40px;
border-radius: 5px;
border: 2px solid #fff;
text-align: center;
font-size: 16px;
color: #fff;
line-height: 2.4em;
cursor: pointer;
}
.button:hover{
background: #fff;
color: rgba(0,0,0,0.0)
}
The reason is because your hover color: was set to transparent, so of course it will be white. Try something simpler like below:
.button {
color: blue;
background: white;
padding: 5px 10px;
border: 3px solid blue;
border-radius: 5px;
text-decoration: none;
transition: all 0.3s;
}
.button:hover {
color: white;
background: blue;
}
button
The problem is that, you have set the text color opacity to 0 so it is like your text is completely transparent. You can simply match it to your body's background color like I did below. No need to mention the opacity, it is 1 by default.
Fixed and working code snippet:
body{
background: #0E80C6;
}
.button{
height: 40px;
border-radius: 5px;
border: 2px solid #fff;
text-align: center;
font-size: 16px;
color: #fff;
line-height: 2.4em;
cursor: pointer;
background: transparent; /* background changed to transparent so it shows the body's background color */
}
.button:hover{
background: #fff;
color: #0E80C6; /* color matched to that of the background */
}
<button class="button">Button</button>
Your issue was you had the opacity of the text color set to 0%. The last letter in rgba means "alpha" or opacity.
body {
background-color: rgba(42, 148, 245, 1.00);
}
.button {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
background-color: transparent;
height: 40px;
border-radius: 5px;
border: 2px solid #fff;
text-align: center;
font-size: 16px;
color: #fff;
line-height: 2.4em;
padding-left: 40px;
padding-right: 40px;
cursor: pointer;
}
.button:hover {
background: #fff;
color: rgba(42, 148, 245, 1.00);/*Set this to whatever you have for the background color. the "1.00" is the opacity"*/
}
<input type="button" value="button" class="button">
RGBA(red, green, blue, alpha)
The problem is you had the opacity(alpha value) of text is 0
body{
background: blue
}
.button{
background: transparent;
height: 40px;
border-radius: 5px;
border: 2px solid #fff;
text-align: center;
font-size: 16px;
color: #fff;
line-height: 2.4em;
cursor: pointer;
}
.button:hover{
background: #fff;
color: blue
}
<button class="button">Button</button>