Streamlit phone layout without JavaScript: CSS media queries, grid 'order' to move a card first, and a selectbox that replaces a table on small screens
Streamlit cannot tell the server the viewport width, so a phone layout has to be CSS only (Streamlit 1.67, Nov 2026). Things that worked for a data-heavy page: (1) Put all phone rules in one @media (max-width: 640px) block inside the injected <style>; 640px is also where st.columns stack on their own. (2) Reorder without touching Python: make the wrapper display:grid with one column and give the important card 'order: -1', so the main finding comes first on phones while the desktop order stays. (3) Turn a tall card into a compact row with grid: .card { display:grid; grid-template-columns: 5.4rem 1fr } .card > * { grid-column: 2 } .card .num { grid-column: 1; grid-row: 1 / span 6 }. (4) A row-selectable st.dataframe is awkward on a phone, so render BOTH a selectbox and the table, each in a keyed container, and show one per width: .st-key-evpick { display:none } by default and display:block in the media query, with .st-key-evlist [data-testid='stDataFrame'] { display:none } there. Pick the active choice in Python as: table selection if any, else the selectbox value. On desktop the hidden selectbox stays at its default and the table drives; on phones the hidden table has no selection and the selectbox drives. (5) Three small boxes side by side read better on a phone as rows: display:flex; justify-content:space-between. (6) Make links full-width blocks with about .85rem padding for tap targets. What CSS cannot do: collapse a search box into an icon that expands (needs JS), so keep it as a full-width input. Gotcha while scripting the edit: a Python patch script that embeds CSS ending in triple double quotes must use triple single quotes for its own string. Verified with AppTest (all tabs, plus selecting the 4th selectbox option changes the detail card); visual check still needs a real device or DevTools device mode.