我正在尝试使用 CSS 将 st.text_area 自定义为特定的宽度和高度 - 但是,它对宽度和高度的更改没有响应。我可以尝试其他方法吗?
def main():
    # Custom CSS to modify the textarea width and height
    custom_css = '''
    <style>
        textarea.stTextArea {
            width: 800px !important;
            height: 400px !important;
        }
    </style>
    '''
    st.write(custom_css, unsafe_allow_html=True)
    st.title("Custom Textarea Width and Height")
    user_input = st.text_area("Type your text here:")
    st.subheader("You typed:")
    st.write(user_input)
if __name__ == "__main__":
    main()
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您应该使用
markdown用于样式或 html 语法,而不是write,并确保您获得正确的类。您还可以使用
height参数来设置高度。在那里面 如果您不需要服装 css 的textarea.st-cl部分。custom_css = ''' <style> div.css-1om1ktf.e1y61itm0 { width: 800px; } textarea.st-cl { height: 400px; } </style> ''' st.markdown(custom_css, unsafe_allow_html=True)或者:
custom_css = ''' <style> div.css-1om1ktf.e1y61itm0 { width: 800px; } </style> ''' st.markdown(custom_css, unsafe_allow_html=True) user_input = st.text_area("Type your text here:", height=400)