I have been trying to find the relevant css that I need to change in Bootstrap to prevent this effect on clicking a button (see attached image)
Any help would much most appreciated!
EDIT : Here is the relevant code :
<div class="btn-group" dropdown container="body">
<button dropdownToggle type="button" class="btn dropdownToggle" style="background-color:#337ab7;color:white;">
Views <span class="caret"></span>
</button>
</div>
EDIT 2 : I managed to remove the border with this code :
.btn:focus,
.btn:active:focus,
.btn.active:focus,
.btn.focus,
.btn:active.focus,
.btn.active.focus {
outline: none;
}
However, there is still an effect when I click on the button (see image below) :
Is it possible to also remove this?
You have to set .btn:focus {outline: 0;}. If you need to remove focus globally just use this :focus {outline: 0;}
For the second question just use
.btn.active,
.btn:active {
box-shadow: none;
}
Most likely the default outline, here's a generic dropdown example with bootstrap 3.3.7 without outline:
button:focus {
outline: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="dropdown">
<button id="dLabel" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dLabel">
...
</ul>
</div>
You may need to add a line of css that over-rides the bootstrap, like:
button {
border:0!important;
}
You will also have to remove the shadowing:
.btn.active, .btn:active {
-webkit-box-shadow: none;
box-shadow: none;
}
Related
I'm far from an HTML wizard but do want to create a simple bootstrap button in html that I can enable and disable. My question is, assuming this is a bootstrap button:
<div class="button" onClick=doSomething >My Button</div>
would this be the proper way to keep the same button from being clicked?
<div class="button disabled" onClick=doSomething >My Button</div>
Thanks
<button type="button" class="btn btn-secondary btn-lg" disabled>Button</button>
Just switch classes btn-primary/btn-secondary and disabled state.
See documentation: Buttons - Bootstrap
You have a rather odd request here. I'm not sure why you aren't using Bootstrap classes, a button element, and the disabled attribute:
function go() {
console.log('went');
}
body {
padding: 30px;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<button type="button" class="btn btn-primary" onclick="go()">Button</button>
<button type="button" class="btn btn-primary" onclick="go()" disabled>Button</button>
That said, you can turn off pointer events for any element with CSS:
function doSomething() {
console.log('clicking happened');
}
.disabled {
pointer-events: none; /* <-- here's your huckleberry */
opacity: 0.65;
}
.button {
display: inline-block;
background: #ddd;
padding: 4px;
margin: 2px;
border: 1px solid #ccc;
cursor: pointer;
}
<div class="button" onClick="doSomething()">"Button"</div>
<div class="button disabled" onClick="doSomething()">Disabled "Button"</div>
I am trying to add fontawesome arrow icon to submit button in Wordpress using ContactForm7. I have this:
[submit class:button "Send a message "]
in css:
.wpcf7-submit:before {
content: '\f30b';
font-family: 'Font Awesome 5 Free' !important;
}
And it doesnt work, any ideas?
I know I'm a bit late to the party, but I've just found an easier option (or at least I thought so!) that helped me get an icon on my submit button.
No pseudo elements needed, you can just insert the element straight into the Contact Form:
<!--add the following instead of [submit] in Contact Form 7-->
<button type="submit" class="wpcf7-submit">Send Message<i class="fas fa-arrow-circle-right"></i></button>
<img class="ajax-loader" src="/wp-content/plugins/contact-form-7/images/ajax-loader.gif" alt="Sending ..." style="visibility: hidden; opacity: 1;">
You can also then add styles to the button like this:
/*Then you can add whatever style you want to your button*/
button.wpcf7-submit {
background: #31D1D3;
padding: 10px 15px;
border: 0;
}
button.wpcf7-submit i {
margin-left: 5px
}
button.wpcf7-submit:hover {
color: white;
}
button.wpcf7-submit:hover i {
color: white;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
<!--just for this example, presume you already have font awesome installed if you're looking to output a button-->
<!--add the following instead of [submit] in Contact Form 7-->
<button type="submit" class="btn primary wpcf7-submit">Send Message<i class="fas fa-arrow-circle-right"></i></button>
<img class="ajax-loader" src="/wp-content/plugins/contact-form-7/images/ajax-loader.gif" alt="Sending ..." style="visibility: hidden; opacity: 1;">
Update:
You can even use Font Awesome Ajax Loader instead of the CF7 one!
/*Then you can add whatever style you want to your button*/
button.wpcf7-submit {
background: #31D1D3;
padding: 10px 15px;
border: 0;
}
button.wpcf7-submit i {
margin-left: 5px
}
button.wpcf7-submit:hover {
color: white;
}
button.wpcf7-submit:hover i {
color: white;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
<!--just for this example, presume you already have font awesome installed if you're looking to output a button-->
<!--add the following instead of [submit] in Contact Form 7-->
<button type="submit" class="btn primary wpcf7-submit">Send Message<i class="fas fa-arrow-circle-right"></i></button>
<i class="fab fa-github ajax-loader" style="visibility: hidden; opacity: 1;"></i>
Update:
Contact Form 7 by default uses an <input type="submit"> element for the submit button. input elements can't use the ::before/::after pseudo elements because input elements don't have child nodes.
You'll need to change your submit button into an actual button (as shown here) for you to be able to add FontAwesome icons to it.
You also need to specify the font-weight property, otherwise the font won't be loaded by the browser.
.wpcf7-submit::before {
content: "\f30b";
font-family: "Font Awesome 5 Free";
font-weight: 900;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<form action="" method="post">
<button type="submit" class="wpcf7-submit">
Send
</button>
</form>
I styled my button everything is cool but can't change the blue color on click.
<button type="button" class="btn btn-primary">Log In</button>
.btn.btn-primary:focus {
background-color: and here color
}
doesn't work
The hover state has priority over the active or focus. You can see it on the snippet as both element has a color change for active, but only on for hover.
.btn:active { background-color: red }
.btn.btn-primary:hover { background-color: green }
<button type="button" class="btn btn-primary">With hover</button>
<button type="button" class="btn btn-secondary">No hover</button>
To solve this, you need to specify the order, and be clear in your selectors.
hover selector needs to be before the active selector.
.btn.btn-primary:hover { background-color: green }
.btn.btn-primary:active { background-color: red }
<button type="button" class="btn btn-primary">Button</button>
You need to override each pseudo-selector for the button that you want to change.
If you want to avoid using !important, then you are going to need to override a couple more selectors that Bootstraps sets. I commented these out in the snippet for simplicity's sake.
.btn.btn-primary {
background-color: orange
}
.btn.btn-primary:active,
.btn.btn-primary:hover,
.btn.btn-primary:focus {
background-color: orange !important;
}
/*
.btn-primary:not(:disabled):not(.disabled).active,
.btn-primary:not(:disabled):not(.disabled):active,
.show > .btn-primary.dropdown-toggle {
background-color: orange;
}
*/
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<button type="button" class="btn btn-primary">Log In</button>
Use
.btn:active {
background-color: red;
}
How can I use cursor: not-allowed on button or a? I tried the following:
.not-allowed {
pointer-events: auto! important;
cursor: not-allowed! important;
}
My button looks like this:
<a class="btn btn-primary btn-lg disabled not-allowed" href="https://www.example.com" role="button">Test</a>
Without the pointer-events is activated, the cursor can not be changed. But if pointer-events: auto, the button or a is clickable. If the pointer-events: none the cursor doesn't change.
Please help me, I despair!
This is actually a bug in Bootstrap
The proposed solutions :
button:disabled {
cursor: not-allowed;
pointer-events: all !important;
}
or if you have this kind of structure :
<li class="disabled">
My Link
</li>
then
li.disabled {
cursor: not-allowed;
}
li.disabled a {
pointer-events: none;
}
Use this:
.not-allowed {
cursor: not-allowed !important;
}
You can wrap your button in span like below
<span>
<button> click me </button>
</span>
Now in css don't allow pointer events on button and make cursor disabled for wrapper.
button {
pointer-events: none;
opacity: 0.7
}
span {
cursor: not-allowed;
}
use onclick="return false;"
.not-allowed{
cursor: not-allowed! important;
}
<a class="btn btn-primary btn-lg disabled not-allowed" onclick="return false;" href="https://www.example.com" role="button">Test</a>
You have a number of options, but not all of them are equal.
Preferably, wrap your element with a div or span and set the cursor on the wrapper and pointer-events on the content. This way you get all benefits without messing with JS.
Second, you can use the attribute disabled on a button, which will make it so that it does not work. You can thenset the cursor on the disabled element.
Lastly, but I don't advise it, is using JS to return false. Even though this works, I don't like it because: the click event is still triggered (i.e. clicking is still possible but the link is not followed through), meaning you also visually think you clicked the button.
.disabled-wrapper {
display: inline-block;
cursor: not-allowed;
}
.disabled-wrapper a,
.disabled-wrapper button {
pointer-events: none;
}
button[disabled] {
cursor: not-allowed;
}
a.disabled.js-test,
button.disabled.js-test {
cursor: not-allowed;
}
<div class="disabled-wrapper"><a class="btn btn-primary btn-lg disabled not-allowed" href="https://www.example.com" role="button">Test wrapper</a></div>
<button class="btn btn-primary btn-lg disabled not-allowed" href="https://www.example.com" role="button" disabled>Test disabled attribute</button>
<a class="btn btn-primary btn-lg disabled not-allowed js-test" href="https://www.example.com" role="button" onclick="return false">Test JS</a>
Most of the time not allowed is not work together with the disabled property.
is any one looking for disable with not allowed property here is code.
<style>
button
{
cursor:not-allowed;
}
</style>
<button disabled>
Click
</button>
I have made the following dropdown button (JSBin). Currently, when the dropdown list is open, and when I hover over the listed items, the button itself changes its colour to dark blue. I don't want this to happen; I want it to change its color to #1abc9c. Does anyone know how to do this?
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
.rb .btn.btn-primary {
background-color: #1abc9c;
border-color: white
}
.rb .btn.btn-primary:hover {
background-color: #2fe2bf;
}
.rb .btn.btn-primary:focus {
outline: none;
-webkit-box-shadow: none;
box-shadow: none;
}
.rb .btn.btn-primary:active {
border-color: white;
background-color: #1abc9c;
}
.rb .dropdown-toggle {
border-color: white !important;
}
</style>
</head>
<body>
<div class="rb">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
</button>
<ul class="dropdown-menu">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
</div>
</body>
</html>
Edit 1: I have a better version here. Now, while pressing the normal button above, we see the colour changes to a slightly darker blue, and when we release the pressing, the colour changes back to a brighter blue. I want to have the same effect on the dropdown button: ie, press the button ==> a slightly darker blue ==> release the button ==> a brighter blue and the dropdown list is shown ==> press the button ==> a slightly darker blue ==> release the button ==> a brighter blue and the dropdown list is hidden.
Does anyone know if it is possible?
Please try this i hope it will helpful to you.
.rb .dropdown:active .btn-primary:active {
background-color: #1abc9c !important;
}
Using chrome developer tools you can isolate the state of the DOM element you want to change, in this case it is
.open>.dropdown-toggle.btn-primary:focus {
background-color: #1abc9c;
}
Try it out in your css and you can see it work
It's normal because you are using Bootstrap. When a button is focused, Bootstrap adds this rule : background-color: #204d74;
So you need to add a background-color:#1abc9c on your .btn-primary when it's :focus like this :
.rb .btn.btn-primary:focus {
outline: none;
-webkit-box-shadow: none;
box-shadow: none;
background-color:#1abc9c;
}