How to target data-testid="stSidebarNavItems" with CSS

As per title.

I am trying to change the on hover color for the data-testid=“stSidebarNavItems”. I am using st.navigation to create the sidbar links.

I tried all the option, but nothing seems to be working?

To highlight individual page links on hover:

div[data-testid="stSidebarNav"] ul[data-testid="stSidebarNavItems"] li a[data-testid="stSidebarNavLink"]:hover {
    border: red solid 2px;
}

Thanks very much :smiley: It works, but not for the text color?

Also, how can I target the color of active/selected nav button? Probably simple question, but I have very little basic understanding of CSS.

div[data-testid="stSidebarNav"]
ul[data-testid="stSidebarNavItems"]
li a[data-testid="stSidebarNavLink"]:hover {
    background-color: #9e2929;
    font-size: 1.02em;
    color: white !important;
}

You’ll need to target the span tag inside the a tag from the previous css snippet:

div[data-testid="stSidebarNav"] ul[data-testid="stSidebarNavItems"] li a[data-testid="stSidebarNavLink"]:hover span {
    color: rebeccapurple;
    font-weight: bold;
}


That one is not simple at all because there is no nice CSS selector to identify which item of that list of pages is the current one.

1 Like

thanks edsaac, appreciate your help!

I will keep digging to see if I can find a solution for “on active color change” as it would be nice to have for what I am working on atm.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.