I'm using Bootstrap and I want to link all button elements to have the same CSS properties as the btn and btn-primary classes.
How can this be achieved? Thanks!
You can adjust the button element itself and copy the CSS properties over from the .btn and .btn-primary.
button {
display: inline-block;
font-weight: 400;
color: #858796;
text-align: center;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: transparent;
border: 1px solid transparent;
padding: 0.375rem 0.75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: 0.35rem;
-webkit-transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-box-shadow 0.15s ease-in-out;
color: #fff;
background-color: #075b8f;
border-color: #075b8f;
}
button:hover {
color: #fff;
background-color: #0773b1;
border-color: #0773b1;
cursor: pointer;
}
button:focus, button.focus {
-webkit-box-shadow: 0 0 0 0.2rem rgba(105, 136, 228, 0.5);
box-shadow: 0 0 0 0.2rem rgba(105, 136, 228, 0.5);
}
<button>Click me</button>
If you do not want to write CSS values for the button element itself, you will need to use JavaScript to apply a class on each button element:
[...document.querySelectorAll('button')].forEach(button => {
button.classList.add("btn-primary");
button.classList.add("btn");
})
.btn, .btn-primary {
color:red;
}
<button>test</button>
<button>test2</button>
Related
Why in Safari (on :hover) not the whole button turns to my hover-color ?
(Something wrong with padding I assume)
--- Result in Safari:
--- Result in Chrome (expected):
.btn,
a.btn{
background-color: #027BFF;
border-color: #007bff;
color: #fff;
border-radius: 0;
padding: 42px 20px;
transition: color .2s ease-in-out,background-color .2s ease-in-out,border-color .2s ease-in-out,box-shadow .2s ease-in-out;
transition-property: color, background-color, border-color, box-shadow;
transition-duration: 0.2s, 0.2s, 0.2s, 0.2s;
transition-timing-function: ease-in-out, ease-in-out, ease-in-out, ease-in-out;
transition-delay: 0s, 0s, 0s, 0s;
}
.btn:hover, a.btn:hover {
background-color: pink;
color: #fff;
box-shadow: 0 0 0 0.25rem rgb(13 110 253 / 5%);
cursor: pointer;
}
<span>Search</span>
I was having a similar issue with :hover in Safari. On hover, my a button was not filling in completely like your example.
I narrowed the bug down to my font-family:
body { font-family: Inter, 'Arial Narrow Bold', sans-serif; }
I have Inter imported via fonts.bunny.net and if I remove Inter and use a system font the :hover behaves as expected. The moment I use an imported font, the issue comes back.
I was able to fix it completely by using switching to Google Fonts instead of fonts.bunny.net
The problem seems to be with Safari's handling of box-shadow ->
.btn,
a.btn{
background-color: #027BFF;
border-color: #007bff;
color: #fff;
border-radius: 0;
padding: 42px 20px;
transition: color .2s ease-in-out,background-color .2s ease-in-out,border-color .2s ease-in-out,box-shadow .2s ease-in-out;
transition-property: color, background-color, border-color, box-shadow;
transition-duration: 0.2s, 0.2s, 0.2s, 0.2s;
transition-timing-function: ease-in-out, ease-in-out, ease-in-out, ease-in-out;
transition-delay: 0s, 0s, 0s, 0s;
}
.btn:hover, a.btn:hover {
background-color: pink;
color: #fff;
/* box-shadow: 0 0 0 0.25rem rgb(13 110 253 / 5%); */
cursor: pointer;
}
<span>Search</span>
I am editing a website template which has the following css for a button class.
.button {
-moz-appearance: none;
-webkit-appearance: none;
-o-appearance: none;
-ms-appearance: none;
appearance: none;
-moz-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, border-color 0.2s ease-in-out;
-webkit-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, border-color 0.2s ease-in-out;
-o-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, border-color 0.2s ease-in-out;
-ms-transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, border-color 0.2s ease-in-out;
transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out, border-color 0.2s ease-in-out;
background-color: transparent;
border-radius: 0.35em;
border: solid 3px #efefef;
color: #787878 !important;
cursor: pointer;
display: inline-block;
font-weight: 400;
height: 6.15em;
height: calc(2.75em + 6px);
line-height: 2.75em;
min-width: 20em;
padding: 0 1.5em;
text-align: center;
text-decoration: none;
white-space: nowrap;
margin:10px;
}
I am trying to increase the font within. Tried playing around with the values of line-height and height but wasn't able to increase the font size. Any ideas?
try font-size:__px whatever pixel value it is
I just added font-size property to CSS. It worked. Pretty Basic :P
All you need to do is utilize the CSS font-size property:
#yourdiv{
font-size:20px;
}
Add this:
size: 20px;
or:
font-size: 20px;
This is my CSS:
.light .contact_form_widget input:focus,.light .contact_form_widget textarea:focus,.light #commentform input:focus,.light #commentform textarea:focus,.light #contactform input:focus,.light #contactform textarea:focus{
transition:all .2s ease-in-out;
-webkit-transition:all .2s ease-in-out;
-moz-transition:all .2s ease-in-out;
-o-transition:all .2s ease-in-out;
-webkit-backface-visibility:hidden
}
Why this CSS transition is not working when I unfocus an input or a textarea? The transition works on links, image-hover-overlays...
[I removed the link, not needed for the question, it was only an example].
EDIT: This is the other part of the CSS (I didn't post it before, I don't know why, probably it was too obvious):
.light .contact_form_widget input:focus,.light .contact_form_widget textarea:focus,.light #commentform input:focus,.light #commentform textarea:focus,.light #contactform input:focus,.light #contactform textarea:focus{
background:#FFF;border:1px solid #BBB;
box-shadow:inset 0 0 5px rgba(0,0,0,0.13);
-webkit-box-shadow:inset 0 0 5px rgba(0,0,0,0.13);
-moz-box-shadow:inset 0 0 5px rgba(0,0,0,0.13)
}
Try like this Demo
CSS:
input[type=text]{
background-color: #f2f2f2;
border:1px solid #ccc;
-webkit-transition: all .2s ease-out;
-moz-transition: all .2s ease-out;
-ms-transition: all .2s ease-out;
-o-transition: all .2s ease-out;
transition: all .2s ease-out
}
input[type=text]:focus {
border-color: #777;
color: #000;
background: #fff;
outline: 0
}
You need to give animation for normal state instead on focus
I have the following CSS / HTML code:
CSS:
#buttons a {
margin: 0 30px;
display: inline-block;
position: relative;
padding: 9px 3px;
-webkit-transition: background 500ms ease-in-out;
-moz-transition: background 500ms ease-in-out;
-ms-transition: background 500ms ease-in-out;
-o-transition: background 500ms ease-in-out;
transition: background 500ms ease-in-out;
}
#buttons a span{
background: #242424;
font-size: 1.7em;
color: #fffae6;
border: 1px solid #fff;
outline: 4px solid #242424;
position: relative;
width: 100%;
height: 100%;
padding: 5px 40px;
-webkit-transition: background 500ms ease-in-out;
-moz-transition: background 500ms ease-in-out;
-ms-transition: background 500ms ease-in-out;
-o-transition: background 500ms ease-in-out;
transition: background 500ms ease-in-out;
}
HTML:
<a class="restaurant_book_button" href="/book"><span>Book Online</span></a>
How it renders in Safari:
How it renders in Chrome:
Any ideas what could be causing this?
Try box-sizing with -webkit prefix in span because you are using padding while your span width is 100%.
Is this a solid, cross-browser way to implement transitions? I have no idea what I could be doing wrong?
Fiddle
html:
<div id="sideBar">
<ul class="sideMenu">
<li>Beat of the Day</li>
<li>Cyborg DB</li>
<li>Hadiaris.com</li>
<li>DriversEd.com</li>
<li>
Controlco
<ul>
<li>GGP</li>
<li>TVA</li>
</ul>
</li>
</ul>
</div>
css:
.sideMenu a {
display: block;
width: 150px;
padding: 5px 5px 5px 10px;
margin: 0px 0px 0px 10px;
border-radius: 50px;
color: black;
-moz-transition: color .9s, -moz-transform .9s;
-webkit-transition: color .9s, -moz-transform .9s;
-o-transition: color .9s, -moz-transform .9s;
transition: color .9s, -moz-transform .9s;
}
.sideMenu a:hover {
box-shadow: inset 0px 0px 5px 0px black;
color: blue;
}
You need to get rid of , -moz-transform .9s in the transition declaration.
.sideMenu a {
display: block;
width: 150px;
padding: 5px 5px 5px 10px;
margin: 0px 0px 0px 10px;
border-radius: 50px;
color: black;
-moz-transition: color .9s;
-webkit-transition: color .9s;
-o-transition: color .9s;
transition: color .9s;
}
.sideMenu a:hover {
box-shadow: inset 0px 0px 5px 0px black;
color: blue;
}
Your transform values are all using the -moz- version. Also, your transition will only work when "unhovering" the way you have it. If you add the transitions to both rules, you'll get the transform on the hover as well.
Updated fiddle
.sideMenu a {
display: block;
width: 150px;
padding: 5px 5px 5px 10px;
margin: 0px 0px 0px 10px;
border-radius: 50px;
color: black;
-moz-transition: color .9s, -moz-transform .9s;
-webkit-transition: color .9s, -webkit-transform .9s;
-o-transition: color .9s, -o-transform .9s;
transition: color .9s, transform .9s;
}
.sideMenu a:hover {
box-shadow: inset 0px 0px 5px 0px black;
color: blue;
-moz-transition: color .9s, -moz-transform .9s;
-webkit-transition: color .9s, -webkit-transform .9s;
-o-transition: color .9s, -o-transform .9s;
transition: color .9s, transform .9s;
}
Your -moz-transform is causing problems. If you just want to animate the color property, you can remove it:
-moz-transition: color .9s;
-webkit-transition: color .9s;
-o-transition: color .9s;
transition: color .9s;
}
Demo: http://jsfiddle.net/C83Yd/1/