List of buttons with minimal spacing

Hi i am new to streamlit. I am creating a list of buttons, but I see gaps between buttons due to some CSS issue. How can i create a list of buttons with minimal gap so that one button end and other’s start are at same without minimal gaps. See in expected pic, how Topics and More vertically side by side.

current:


expected:

Just stumbled across this custom component another streamlit user created. Maybe this can solve you problem:

Thanks. Used this:
Now the list is coming like this

Code:

# 1. Import at the top of the file
from streamlit_option_menu import option_menu

# 2. Get unique PDF names from citation_data
citation_data = st.session_state.get('uss_poc_citation_data', [])
unique_pdfs = []
seen = set()
for citation in citation_data:
    pdf = citation.get('filename', 'Unknown')
    if pdf not in seen:
        unique_pdfs.append(pdf)
        seen.add(pdf)
st.session_state.uss_poc_search_pdf_list = unique_pdfs

# 3. Show vertical list of PDF options using option_menu
if unique_pdfs:
    # Create a menu (no header, no icons)
    with st.container():
        selected_pdf = option_menu(
            menu_title="",  # No header
            options=unique_pdfs,
            icons=[""] * len(unique_pdfs),  # No icons
            default_index=unique_pdfs.index(st.session_state.get('uss_poc_selected_pdf', unique_pdfs[0]))
                      if unique_pdfs and st.session_state.get('uss_poc_selected_pdf') in unique_pdfs else 0,
            orientation="vertical"
        )

        # Handle selection like a button click
        if selected_pdf != st.session_state.get('uss_poc_selected_pdf'):
            st.session_state.uss_poc_pdf_selection_method = 'citation'
            st.session_state.uss_poc_from_query_citation = False
            st.session_state.uss_poc_selected_pdf = selected_pdf
            if 'uss_poc_pdf_citation_indices' not in st.session_state:
                st.session_state.uss_poc_pdf_citation_indices = {}
            st.session_state.uss_poc_pdf_citation_indices[selected_pdf] = 0

Can we customise this?
I want to remove the triangular icon on each row, change background color and selection box color from blue to red. I tried custom CSS but it is not working for some reason.

Are you able to share a sample of how you’re creating the buttons originally? What you’ve shown in your screenshot seems to have the buttons spaced much further apart than if you’d just done something like

st.button("File 1", type="secondary")
st.button("File 2", type="secondary")

In streamlit_option_menu you can pass a styles parameter to option_menu. The docs give the following example.

# 3. CSS style definitions
selected3 = option_menu(None, ["Home", "Upload",  "Tasks", 'Settings'], 
    icons=['house', 'cloud-upload', "list-task", 'gear'], 
    menu_icon="cast", default_index=0, orientation="horizontal",
    styles={
        "container": {"padding": "0!important", "background-color": "#fafafa"},
        "icon": {"color": "orange", "font-size": "25px"}, 
        "nav-link": {"font-size": "25px", "text-align": "left", "margin":"0px", "--hover-color": "#eee"},
        "nav-link-selected": {"background-color": "green"},
    }
)

The example should give you an idea of how to change the colours you need.

If you pass the following then the default icon won’t show.

styles={
    "icon": {"display": "none"}
}