CSS Adaptation of Hover Interaction

I'm currently developing a user interface using Shiny and I've been working on creating some visually appealing buttons. I've managed to customize the colors as desired, but now I'm facing an issue with getting the button to darken when hovered over, similar to the default buttons.

Here is the function that I have created for these stylized buttons:

    dateButton <- function(id, label) {
    actionButton(inputId = id, label = label, style = "color: white;
    background-color: darkblue;
    border-radius:15%;
    border-color: white;
    .hover {
    box-shadow: inset 0 0 100px 100px rgba(255, 255, 255, 0.1);
    }")
    }

I believe the issue lies within the .hover section where formatting seems to be incorrect. Any suggestions or resources would be highly appreciated.

Here's a code representation:

    library(shiny)
    dateButton <- function(id, label) {
    actionButton(inputId = id, label = label, style = "color: white;
    background-color: darkblue;
    border-radius:15%;
    border-color: white;
    .hover {
    box-shadow: inset 0 0 100px 100px rgba(255, 255, 255, 0.1);;")

    ui <- fluidPage(
      dateButton("my_button", "B1"),
      actionButton("default_button", "B2")
    )

    server <- function(input, output, session) {
  
    }

    shinyApp(ui, server)
}

After running the code, B2 behaves correctly upon hovering, while B1 does not exhibit the expected behavior.

Answer №1

Adding the :hover pseudo-class selector to an object's inline style attribute may not be feasible. It is recommended to either include it within a <head><style>... section or link to an external style sheet for smoother functionality. The first option is demonstrated below:

library(shiny)
dateButton <- function(id, label) {
  actionButton(
    inputId = id,
    label = label
  )
}

ui <- fluidPage(
  tags$head(tags$style(HTML("
                            #my_button {
                              background-color: darkblue;
                              color: white;
                              border-radius:15%;
                              border-color: white;
                            }
                            #my_button:hover {
                              box-shadow: inset 0 0 100px 100px rgba(255, 255, 255, 0.1);
                              font-weight: bold
                            }
                            "))),
  dateButton("my_button", "B1"),
  actionButton("default_button", "B2"))

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

Edit - creating a shared class for buttons

To apply the same styling to multiple buttons, introduce a class attribute in your function call and adjust the CSS accordingly:

library(shiny)
dateButton <- function(id, label) {
  actionButton(
    inputId = id,
    class = "hover-button",
    label = label
  )
}

ui <- fluidPage(
  tags$head(tags$style(HTML("
                            .hover-button {
                              background-color: darkblue;
                              color: white;
                              border-radius:15%;
                              border-color: white;
                            }
                            .hover-button:hover {
                              box-shadow: inset 0 0 100px 100px rgba(255, 255, 255, 0.1);
                              font-weight: bold
                            }
                            "))),
  dateButton("my_button", "B1"),
  actionButton("default_button", "B2"))

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are some ways to slow down the speed of a canvas animation?

I am currently working on an animation project using JavaScript and canvas. I have a reference fiddle where objects are generated randomly and fall from the top right corner to the bottom left corner, which is fine. However, the issue is that the objects a ...

Guide to setting a white background color specifically for a lightbox in Angular

I want to change the background-color to white for my gallery items. Currently, I am using the following code to open the full-screen view: this.lightbox.open(0, 'lightbox1', { panelClass: 'fullscreen'}) Can someone please guide me on ...

IDs within CSS remain consistent across different media queries

Having trouble updating my media query properly. Check out this example HTML: <!DOCTYPE HTML> <html> <head> <link rel="stylesheet" type="text/css" href="main.css"> <title>Test </title> </hea ...

Utilizing nls for AIC calculations in the R environment

I'm encountering an issue with calculating the AIC. I have estimated parameters for three models: "mod_linear" which is a linear model, and "mod_exp" and "mod_logis" which are non-linear models. Initially, I used the AIC() function: AIC(mod_linear, ...

The Bootstrap navigation bar fails to expand

After extensive searching, I still can't figure out why my bootstrap menu isn't opening as expected. I made sure to link JQuery first to try to resolve the issue, but it doesn't seem to have made any difference. I'm starting to wonder ...

Combining the values of a column and saving the result in a newly created column at the end using R programming

Let's say I have a dataset col1 df= 1 2 3 4 How can I achieve the following in R programming? col1 col2 df= 1 2 3 4 10 (sum of col1) ...

What is the procedure for eliminating the underline located at the bottom of the table?

Can anyone please assist me with removing the underlines at the end of the table? I find it quite unattractive and can't seem to figure out how to remove it. https://i.sstatic.net/stvHt.png https://i.sstatic.net/YYbrX.png Below is the code snippet ...

Is there a way to eliminate this pesky margin?

please check out this: https://jsfiddle.net/desytec/73qdtejg/1/#&togetherjs=w3lvLQi0v6 This displays the following table definition: <table id="semana" class="table table-striped dt-responsive table-bordered display ...

Is there a way in JavaScript to track changes in CSS properties such as transitioning from "display:none" to "display:block"?

Is there a way to detect when the CSS property "display" of an image is changed by another JavaScript script or function and then execute some JS code? I tried using $(this).bind('propertychange', function(){}) but it doesn't work, and setIn ...

What is the best way to customize the look of the v-calendar component in Vue.js?

I've recently started a project that involves Vue.js, and I needed to create a datepicker for it. After some research, I opted to utilize the v-calendar package. The implementation of the component went smoothly and functioned as expected right out o ...

Adding a table element into a specific cell within a data frame

I am working on generating tables for each row in a data frame named df. My goal is to include these tables as values in a new column in the database, with each row having a unique table assigned to it. However, when attempting to insert a table into the d ...

The HTML chart is not compatible with a compact Android WebView

I am facing an issue with resizing a circle diagram from Chart.js inside a small WebView. The Width and Height of the WebView are set to 25dp, but the circle diagram does not resize properly to fit this size. Here is the HTML code for the circle chart: & ...

Maintain a fixed element and enable the rest of the elements to scroll as the mobile browser address bar collapses while scrolling upwards

Currently facing a challenge where I want the background image to remain static while the address bar and content underneath scroll up. The image occupies 90% of the view height, and although I've prevented it from resizing and jumping when the addres ...

Tips on avoiding this issue: negative subscripts should only be paired with zeros

Here's an example I'm working with: x=c(NA, 2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -2, 2, -14, -15, -16, -17, 2, -19, -20) g= head(x[!is.na(x)], 13) I'm trying to avoid using values already assigned to variable g. ...

Tips for adjusting the height of both an iframe and a div to fit perfectly at 100% combined

Struggling to make an iframe and div both have 100% full height on the page? I need a footer menu with 280px height, leaving the rest of the page for the iframe. After extensive research, it seems like jQuery might be necessary as CSS Flex didn't wor ...

A div set to absolute positioning and a width of 100% will exceed the boundaries of a Bootstrap 4

I am attempting to position a div with 100 percent width within a Bootstrap 4.1 col using absolute positioning in order to attach it to the bottom. However, I am encountering an issue where it overflows on the right side of the screen. I have tried assigni ...

Selectors within 'not' in document.querySelectorAll are failing to function as expected

I've been attempting to find a way to replace the jQuery .not() function with native JavaScript, but so far my attempts using document.querySelectorAll have not been successful. Here is what I am trying to achieve - converting this jQuery selector in ...

How do I integrate a button into my grey navigation bar using tailwindcss in REACT?

Is it possible to integrate the - button into the gray bar? I am encountering an issue where my blue button extends beyond the borders of the gray bar in the image provided. export default function App() { ... return ( <div className="text-md fon ...

Revamp the website's design

I am looking to revamp the color theme of my website with just a click of a button. Can someone provide me with a link to a reference website where I can get some inspiration? ...

I find it confusing how certain styles are applied, while others are not

Working on my portfolio website and almost done, but running into issues with Tailwind CSS. Applied styling works mostly, but some disappear at certain breakpoints without explanation. It's mainly affecting overflow effects, hover states, and list sty ...