Summary
I would like to add an image at the top of the page, in the position of the image highlighted in light blue with the motif:
how to do this ?
I would like to add an image at the top of the page, in the position of the image highlighted in light blue with the motif:
how to do this ?
import streamlit as st
st.set_page_config(layout="wide")
# Custom HTML/CSS for the banner
custom_html = """
<div class="banner">
<img src="https://img.freepik.com/premium-photo/wide-banner-with-many-random-square-hexagons-charcoal-dark-black-color_105589-1820.jpg" alt="Banner Image">
</div>
<style>
.banner {
width: 160%;
height: 200px;
overflow: hidden;
}
.banner img {
width: 100%;
object-fit: cover;
}
</style>
"""
# Display the custom HTML
st.components.v1.html(custom_html)
# Sidebar content
st.sidebar.header("Sidebar Title")
st.sidebar.subheader("Subheading")
st.sidebar.text("Sidebar content goes here.")
# Main content
st.title("Main Content")
st.write("Welcome to my Streamlit app!")
st.write("This is the main content area.")
So i set mode to wider one
and added a banner there
May be it works?
You might want to target the decoration element on top.
import streamlit as st
# Sidebar content
st.sidebar.header("Sidebar Title")
st.sidebar.subheader("Subheading")
st.sidebar.write("Sidebar content goes here.")
# Main content
st.title("Main Content")
st.write("Welcome to my Streamlit app!")
st.write("This is the main content area.")
# JS code to modify te decoration on top
st.components.v1.html(
"""
<script>
// Modify the decoration on top to reuse as a banner
// Locate elements
var decoration = window.parent.document.querySelectorAll('[data-testid="stDecoration"]')[0];
var sidebar = window.parent.document.querySelectorAll('[data-testid="stSidebar"]')[0];
// Observe sidebar size
function outputsize() {
decoration.style.left = `${sidebar.offsetWidth}px`;
}
new ResizeObserver(outputsize).observe(sidebar);
// Adjust sizes
outputsize();
decoration.style.height = "3.0rem";
decoration.style.right = "45px";
// Adjust image decorations
decoration.style.backgroundImage = "url(https://img.pokemondb.net/sprites/emerald/normal/pikachu.png)";
decoration.style.backgroundSize = "contain";
</script>
""", width=0, height=0)
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.