How do I change background color of all the forms differently?

Hi community!
While looking for the solution to the above question, I have found this solution from the streamlit community forum. Wonderfully, It works! But it changes all forms background with one common color that I define. How do I control this behaviour for each form??
I want to color these form by individually selecting them.

import streamlit as st

with st.form("My form"):
    first = st.text_input("First name")
    last = st.text_input("Last name")
    if st.form_submit_button("Submit"):
        st.write(first+" "+last)

css="""
<style>
    [data-testid="stForm"] {
        background: LightBlue;
    }
</style>
"""
st.write(css, unsafe_allow_html=True)

#form #streamlit #streamlitform

You can use the pseudo class nth-child().

To target the first child.

[data-testid="stForm"]:nth-child(1) {
    background: LightBlue;
}

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