I’m using CSS to style my applications. I’ve found that I need to repeatedly do more work with actionButtons because they come with default CSS classes whether I want them to or not. Take a look at this example:
library(shiny)
ui <- fluidPage(
tags$head(
tags$style(HTML("
.redbutton {
background-color: red;
}
"))
),
actionButton("button1", "Hover", class = "redbutton")
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
The button has the redbutton
class applied, as I specified. However, the default CSS classes include on-hover and on-click behavior, changing the color of the button when hovered even though I do not desire this behavior.
Can this be avoided? I’d prefer not to add specific instances of ‘:hover’ into my css sheet for every class, just to disable the default behavior.
2
Answers
One possibility is to do a function for a basic button:
But be aware that such a basic button has some CSS styles defined by the browser, and that’s rather ugly. So you should define a base class for your custom buttons.
Another variant is to remove the unwanted CSS class, client-side, with javascript.
Include this in your HTML head by adding it to your
tags$head
function:In this case, removing the ‘btn-default’ class should do the trick.
Note that CSS also offers a
pointer-events: none
declaration to prevent triggering the hover style (but also other effects like cursor-shape).