【问题标题】:How to change the height of streamlit sidebar如何更改streamlit侧边栏的高度
【发布时间】:2022-11-29 18:05:32
【问题描述】:

我尝试了几个变通方法来使用css更改流线型侧边栏的高度。我的方法之一是下面的代码,但它并没有解决我的问题。我在streamlit discussion forum 中找到了一些建议的方法,但这些方法也没有帮助。有人可以帮忙吗?

import streamlit as st 


st.markdown(
    """
    <style>
    [data-testid="stSidebar"][aria-expanded="true"] > div:first-child {
        height: 80% ;
    }
    [data-testid="stSidebar"][aria-expanded="false"] > div:first-child {
        height: 80%
    }
    </style>
    """,
    unsafe_allow_html=True,
)


st.sidebar.markdown("Adjust sidebar height")

【问题讨论】:

    标签: css streamlit


    【解决方案1】:

    试试这个代码看看它是否解决了你的问题。我认为应该。您必须使用开发工具密切关注这些类。

    笔记:通过将 !important 添加到您的 css 规则将覆盖默认的 css。我认为有了这个你就可以开始了。

    import streamlit as st
    
    
    st.markdown("""
        <style>
          section[data-testid="stSidebar"][aria-expanded="true"]{
            height: 80% !important;
          }
          section[data-testid="stSidebar"][aria-expanded="false"]{
            height: 80% !important;
          }
        </style>""", unsafe_allow_html=True)
    
    st.sidebar.markdown("Adjust sidebar height")
    

    输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      • 2012-07-20
      • 1970-01-01
      相关资源
      最近更新 更多