I have tried two different iterations of customizing width of a specific button. Both iterations don’t seem to work. If the customization is applied without specifying a button, it applies to the whole page successfully, but that is not the goal. Following are the 2 different iterations, both which don’t seem to work.
# Custom CSS to inject contained in a <style> tag
button_custom_css = """
<style>
div[data-testid="stButton"][id="unique-clear-button"] > button {
width: 150px; /* Set your desired width */
}
</style>
"""
# Add custom CSS to the top of your app (only needs to be done once)
st.markdown(button_custom_css, unsafe_allow_html=True)
# Your existing button creation code
columns = st.columns(7)
with columns[3]:
clicked = st.button("clear", key="unique-clear-button")
if clicked:
modal.close()
st.session_state['button_clicked'] = True
and
# Custom CSS to inject contained in a <style> tag
button_custom_css = """
<style>
/* Target the button with the specific key */
button[data-baseweb="button"][key="unique-clear-button"] {
width: 150px; /* Set your desired width */
}
</style>
"""
# Inject custom CSS
st.markdown(button_custom_css, unsafe_allow_html=True)
If is applied without targeting a specific button, it works. Please advise. Thanks.
App is running locally.
Python 3.11, Streamlit, version 1.29.0