首页 > 解决方案 > 如何在固定的背景图像下方滚动

问题描述

我对 html 和 css 真的很陌生,所以如果问题听起来很基本,请原谅。

我想要实现的是我在页面顶部固定了一个背景图像。我希望一切都在这个背景图像下方滚动。bg 的代码是

def set_png_as_page_bg(png_file):
    bin_str = get_base64_of_bin_file(png_file) 
    page_bg_img = '''
    <style>
    .stApp {
    background-image: url("data:image/png;base64,%s");
    background-size: contain;
    background-repeat: no-repeat;
    background-attachment: scroll;
    }
    </style>
    ''' % bin_str
    
    st.markdown(page_bg_img, unsafe_allow_html=True)
    return

在此处输入图像描述

但是,我希望文本在图像下方滚动。有一个简单的技巧吗?如果有人可以为这个问题提供资源,我也将不胜感激。

P:S: 我也试过 '''background-attachment: scroll''' 但背景不随内容滚动。

标签: pythonhtmlcss

解决方案


你有没有尝试过

<style>
.stApp {
background-image: url("data:image/png;base64,%s");
background-size: contain;
background-repeat: no-repeat;
background-attachment: fixed;
overflow-y: scroll;
}
</style>

并设定高度?


推荐阅读