Changing Bootstrap 4.1 .btn-outline-primary background when clicked and active? - html

I am currently using a Bootstrap 4.1 button with the class being .btn-outline-primary. In its regular state, the button has a white background with blue text. However, when you hover over the button, the colors are inverted such that the background is blue and the text is white.
The active state of this button is only a highlighted border (with button styling the same as inactive state - white background blue text) and I would like to make it so that when the button is clicked, the button remains in the same style as when the button is hovered.
However, I do not have access to the hover class of the button since it is a bootstrap button and I am wondering how I can achieve this? Here is the button:
<button class='btn btn-outline-primary max-w-250 mx-1 my-1' type='button' id='MyButton' name='happyButton'>
<div class='d-flex flex-column justify-content-center align-items-center overflow-none'>
<div class='ButtonText line-height-16'>"Text Line One"</div>
</div>
</button>
I have tried using css styling using :focus to change the background color, however, this just over-powers the text since the text does not invert and the background now matches the text color.
.btn-outline-primary:focus{
background-color: #18f;
}

I'm not a huge Bootstrap user or I'd look up the relevant classes for you. Instead, I'll walk you through the steps to find them yourself using DevTools. I'll be using Chrome, but the steps are similar for Firefox and Safari.
In a browser (again, preferably Chrome) where the button is rendered, right click on that button. From the menu, select Inspect.
The box that comes up should be on an elements tab, displaying your html. Confirm that the button is highlighted in that display. If it isn't, click on the button's html to highlight it.
The right side of the newly opened box should be a pane describing the selected element, and should be on the Styles tab. Confirm that the css rules that you'd expect to apply to the button are there.
Near the top of that pane, next to the filter box, there is a small button labeled :hov. Clicking that button displays the various pseudoclasses, like :hover, that can be applied to your element. Check the :hover checkbox.
The :hover rules should now display in the css rules list below. Find the relevant declaration (.btn-outline-primary:focus or something similar) and copy the rules it contains. You can then, in your own css, write
.btn-outline-primary:active {
[whatever rules you copied]
}
I have two addenda:
If that doesn't work, go through the first four steps again, this time selecting the :active pseudoclass. If the rules you added are showing up in your rules list (they may be way down!) but aren't working, you have an issue with css specificity and should look that up
I have written this assuming that, when talking about an active button, you were using the term in the technical css sense, which is a change that only lasts so long as the button is held down. If you want the button to change permanently after it is clicked, you will need to use something outside of css: either use some Javascript to update the classes on the button or change it up and use a checkbox

Related

How to have 3 different conditional border colors?

I need to style an icon button with 3 different border colors, one for regular state, one for on hover, and another one for when the icon is clicked. I am using react, and right now I have a function that checks if the current button is the one that is selected and that works for regular and on clicked, I also added the onHover color but if that button is the on that is active you can't tell because on hover takes over, you can't see the clicked border until you move the mouse away. How to go about this?
you need 3 style declarations
.button {}
.button:hover {}
.button.selected{}
If you write them in exactly this order, then the button's selected style won't overridden by hover as the declaration for selected comes after declaration for :hover state and won't be overridden by it.
It's tough to tell without seeing your code, but it seems like you want both borders for active and hover states to show at the same time.
Since you can only have one border on an element at a time, one state will always overwrite the other.
There are some effects you can use with other CSS properties so that users can tell when a button is both active and being hovered:
outline - outline is similar to border and the two can exist at the same time (outline will probably only work if the buttons are rectangular because it doesn't adhere to border-radius)
box-shadow - this could be an easy way to add a hover effect underneath the element and its border
pseudo-element - This one is more complicated but adds the most flexibility - perhaps adding a ::before or ::after element to the button, positioning it absolute behind the element, and have that behave separately based on whether the button is active or hovered.
I usually use CSS's :hover feature along with the framework (e.g. react)... there are some good examples online where this feature doesn't just change color, but present some type of animation to help the link/button stand out:
https://www.proglobalbusinesssolutions.com/css-hover-effects/#:~:text=A%20CSS%20hover%20effect%20causes%20a%20graphical%20interface,on%20the%20web%20page%20and%20improve%20site%20interactivity
You might also consider this answer: How can I access a hover state in reactjs?

Button CSS state - keep hover colour on active page

I've got a button on my homepage www.example.com pointing to the page B -> www.example.com/page-B
I'm using CSS for the :hover state, so when I hover over the button on the homepage, it turns red.
But what I'm trying to achieve is that the button turns red and stays red when it's clicked and reaches the target page www.example.com/page-B
I was hoping to get it done with either :active or :focus states, but that won't work.
How can I achieve this?
When a button is clicked focus goes to that button. So the styles in button's :focus pseudo-class is applied. But as soon as user clicks another button or change the focus by hitting the tab key, your button lose it's state of "focus".
One option available is using the :visited pseudo-class. You need to wrap your button around anchor tag(<a></a>). Assume you gave a class .link to the anchor tag.
<a href="https://example.com/page-b" class="link">
<input type="button" value="next page" />
</a>
Then the css should be,
.link:visited > button {
color: blue;
}
Notice that I targetted child elements which are buttons under anchor elements. I did that because buttons don't have a :visited pseudo-class which you can use directly. But, according to MDN,
For privacy reasons, the styles that can be modified using this selector are very limited.
So I don't think you can use this approach to make you background red (I tried but doesn't worked). Also, even user revisited your site or reloaded the page, you button stay, ":visited" styled once the user visit the link as that's the way anchor element works.
My suggestion is you should use javascript here. I don't know about wordpress much and I don't know whether you can use js in wordpress or not. But usually you may have the ability to use <script> tag even in wordpress.
My approach...
function nextpage() {
window.open("https://www.example.com/page-b", "_blank");
document.getElementById("next").style.backgroundColor = "red";
}
<input type="button" value="next" onclick="nextpage()" id="next" />
Even I put a snippet it won't work in stackoverflow maybe due to security policy but this should work in real life. I open "example.com/page-b" in a new tab as I opened it in the same tab
"example.com" tab will be closed and when user reopen the tab, button's styles will get lost.
If you want to persist button's red background, then use js, set a cookie when user click the button and style the button as visited if the cookie exist when user reload the page.

HTML5 native input type="time" element, how to locate pseudo element / style dropdown in Chrome?

Chrome has introduced an updated look to their styles, including time and date picker elements that have a dropdown / overlay element to them.
I'm specifically attempting to style an input type="time" element. Here is a demo of the native element. Worth noting is under Chrome 83 that it shows the updated dropdown page for selections.
Specifically, the dropdown shown above (the 00 and 00 text, with blue backgrounds, on an overlaid element) is what I would like to style or modify in some way.
I have enabled the shadow DOM option within the Google Chrome DevTools. I've been able to identify the pseudo elements for things like the input fields and icons and such, but not the dropdown.
It is difficult to provide further demonstrations or links since this is simply a native input. However, this is an example of the pseudo elements I can see on the basic native input.
My use-case is the app I'm using this for is for uses a dark UI color scheme, and this white popup element is very jarring. I prefer the native HTML input (especially with the keyboard accessibility of selecting the hour / minute / 12hour format quickly) over a custom timepicker.
Ideally I would not want to do anything too hacky here -- am I even approaching this in the right way? Want this not to break whenever Chrome updates.
You cannot change the style of time or datepicker dropdown as per chrome FAQ
https://developers.google.com/web/updates/2012/08/Quick-FAQs-on-input-type-date-in-Google-Chrome#how_do_i_change_the_appearance_of_the_date_picker
I suggest you to switch over to some custom or bootstrap controls.
If you dont want the dropdown to be displayed, you could add a css rule to hide the icon, when you click that icon is when the dropdown gets displayed.
This rule should work
input[type="time"]::-webkit-calendar-picker-indicator {
display: none;
}

custom bootstrap button color background erroneous onclick

Within Twitter Bootstrap there is a selection of buttons that one can choose from (as seen here: http://twitter.github.com/bootstrap/components.html). For our project, we opted to use a yellow color that was not included in the default set. A simple matter to simply create a new css class which included the colors I wanted. However, when the button is pressed in, the background color returns to the default grey background color instead of a like-background color as is seen with the other buttons on click. Did I miss something during the creation of the button?
example of issue (taken in FF):
You need to specify your new color with the :active pseudo selector. When you press a button it gets "active" and the :active selector kicks into play. When you release the mouse button the element stops being active and the element style reverts back to normal. Sort of like the :hover pseudo selector, when you're hovering the pointer over something.
i found this question via google.
recommend a article,must do some help
http://rubysource.com/how-to-customize-twitter-bootstrap%E2%80%99s-design-in-a-rails-app/

If we hover over the Icon in AdvanceDataGrid, item hovering effect (slight highlighting) does not appear?

Hovering effect on AdvanceDataGrid doest not appear if we take mouse cusor over the icon of item. any solution?
You can use a button inside your renderer and make use of these styles on button:
overIcon
downIcon