简体   繁体   English

Shiny checkboxGroupButtons css 选中时的不同颜色

[英]Shiny checkboxGroupButtons css for different color when checked

I would like to have individual checkboxes that are part of a group change color when they are checked.我想让作为组一部分的单个复选框在被选中时改变颜色。 I've been able to style them when unchecked and when they are hovered, but the pseudoclass for checked doesn't seem to work.我已经能够在未选中和悬停时设置它们的样式,但已选中的伪类似乎不起作用。 The pseudoclass for "active" causes a color change on mouse-down, but it reverts on mouse up (ie it is only that color while the mouse button is held down). “active”的伪类导致鼠标按下时颜色发生变化,但它在鼠标弹起时恢复(即,只有按住鼠标按钮时才显示该颜色)。

Note that this example is for just one of the buttons.请注意,此示例仅适用于其中一个按钮。 I will want each of them to become a different color when checked.我希望它们中的每一个在检查时都变成不同的颜色。

library(shiny)
library(shinyWidgets)


ui <- fluidPage(
  
  tags$head(
    tags$style(HTML("

.btn-group-toggle:nth-child(1) .btn-custom-class {
  background: green !important;
  color: black !important;
  border: red !important;
}


.btn-group-toggle:nth-child(1) .btn-custom-class:hover {
  background: yellow !important;
  color: black !important;
  border: red !important;
}

.btn-group-toggle:nth-child(1) .btn-custom-class:checked {
  background: red !important;
  color: black !important;
  border: red !important;

}

.btn-group-toggle:nth-child(1) .btn-custom-class:active {
  background: red !important;
  color: black !important;
  border: red !important;

}"
    ))
  ),

checkboxGroupButtons(
  inputId = "cluster_groups",
  label = "Clusters Displayed",
  choiceNames = c("1", "2", "3", "4", "5", "6"),
  choiceValues = 1:6,
  #selected = c("1", "2", "3", "4", "5", "6"),
  status = "custom-class"
),
)

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

shinyApp(ui, server)

When you click the button, it adds a class "active" to ".btn-group-toggle:nth-child(1).btn-custom-class" so you can use this class to replace ":checked" :当你点击按钮时,它会添加一个 class "active"".btn-group-toggle:nth-child(1).btn-custom-class"所以你可以使用这个 class 来替换":checked"

.btn-group-toggle:nth-child(1) .btn-custom-class.active {
  background: red !important;
  color: black !important;
  border: red !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM