Change placeholder color of textInput shiny widget

大城市里の小女人 提交于 2020-02-24 05:36:13

问题


with some CSS code found in different old posts on Stackoverflow I managed to change the placeholder colour of every selectizeInput and selectInput widget of my shinyapp, but it seems that this code doesn't work for the textInput widgets.

Below you can find a basic reproducible example:


library(shiny)

ui <- fluidPage(

  tags$style(HTML("::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
                   color: red;
                   opacity: 1; /* Firefox */}

                  :-ms-input-placeholder { /* Internet Explorer 10-11 */
                  color: red;}

                  ::-ms-input-placeholder { /* Microsoft Edge */
                  color: red;
                  }")),

br(),

  selectizeInput(inputId = "one",
                 label = NULL,
                 choices = c("Letters" = "", "A", "B", "C"),
                 selected = ""),

br(),

  textInput(inputId = "two",
            label = NULL,
            placeholder = "Numbers",
            value = "")

)

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

}

shinyApp(ui, server)

As you can see, the placeholder of the textInput widget remains gray, while I would like it to be red as well.

Thank you in advance for your help!


回答1:


It seems plausible that your problem lies purely in adding your CSS, since doing

var q = document.createElement("style");
q.innerHTML = `::placeholder { color: red }`;
document.body.appendChild(q)

on the selectize demo page does indeed color the placeholder text red.

As for the second question, for targeting a specific element you want your selector to be like

#e6-selectized::placeholder { color: red }

(note the suffix)



来源:https://stackoverflow.com/questions/57679227/change-placeholder-color-of-textinput-shiny-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!