Summary
I want to create a paragraph style sentence with user inputs in between them as in the picture. However, the input widget and text are misaligned. How to fix it?
Steps to reproduce
Code snippet:
# Define a style for no wrapping
style = "display: inline-block; vertical-align: middle; white-space: nowrap; font-family: 'Inter'; font-size: 40px; font-weight: medium;"
# Add some blank space at the top
# Add custom CSS for vertical alignment and font styling
st.markdown("""
<style>
.st-dd, .stTextInput > div > div > input, .stButton > button, .stSlider > div {
vertical-align: middle !important;
font-family: 'Inter';
font-size: 40px;
font-weight: 500;
}
.stTextInput > div > div > input {
margin-top: 5px !important;
}
</style>
""", unsafe_allow_html=True)
st.write("##")
cols1 = st.columns([1, 3, 1, 2, 1])
cols1[0].markdown(f"<div style='{style}'>I am a</div>", unsafe_allow_html=True)
job_title = cols1[1].selectbox("", job_titles, format_func=lambda x: "", key='job_title')
cols1[2].markdown(f"<div style='{style}'>with</div>", unsafe_allow_html=True)
experience = cols1[3].selectbox("", years_of_experience, format_func=lambda x: "", key='experience')
cols1[4].markdown(f"<div style='{style}'>years of experience</div>", unsafe_allow_html=True)
cols2 = st.columns([2, 1, 1, 1, 2])
cols2[0].markdown(f"<div style='{style}'>who currently earns RM</div>", unsafe_allow_html=True)
current_salary = cols2[1].number_input("", value=0, format="%d", key='current_salary')
cols2[2].markdown(f"<div style='{style}'>per month with</div>", unsafe_allow_html=True)
num_past_employments = cols2[3].selectbox("", past_employments, format_func=lambda x: "", key='num_past_employments')
cols2[4].markdown(f"<div style='{style}'>past employments</div>", unsafe_allow_html=True)
cols3 = st.columns([2, 1, 2])
cols3[0].markdown(f"<div style='{style}'>that aims to earn RM</div>", unsafe_allow_html=True)
expected_salary = cols3[1].number_input("", value=0, format="%d", key='expected_salary2')
cols3[2].markdown(f"<div style='{style}'>per month.</div>", unsafe_allow_html=True)