i am trying to change font using css but its not changing
with open('styles2.css') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
st.markdown("<h1 class='Title' >Education</h1>", unsafe_allow_html=True)
# Sample video dictionary (replace with your video data)
with st.sidebar:
selected = option_menu(
menu_title="", # required
options=[" What is Stocks?", "How Stock Price Moves?", "Fundamental Analysis", "Technical Analysis","Candlestick Chart","Indicators"], # required
menu_icon="cast", # optional
default_index=0, # optional
)
if selected == " What is Stocks?":
st.markdown("<h2 class='Heading' >What is Stocks?</h2>", unsafe_allow_html=True)
st.markdown("<p class='Para'>A stock is essentially a piece of ownership in a company. When a company decides to go public, it divides its ownership into units called shares. These shares are then sold to investors on a marketplace called a stock exchange.</br>Think of a stock exchange like a giant marketplace where buyers and sellers come together to trade stocks. The exchange sets the rules and regulations for trading, and ensures that all transactions are conducted fairly and efficiently.</br>Here's an analogy: imagine a company as a pizza. When the company goes public, it's like cutting the pizza into slices (shares). These slices are then sold to people (investors) on a platform (stock exchange).</p>", unsafe_allow_html=True)
image = "stockX.png"
st.image(image, use_column_width=True,clamp=True,)
Have you verified that the path to your font files in the src: url("fonts/YourFont.ttf"); declaration is correct relative to your CSS file or the HTML file?
If your CSS file is located in a different directory than your fonts, you’ll need to adjust the path accordingly.
But, if you can host them on a different website somewhere (even github directly should work), rather than inside your streamlit app itself, and use that external url, I think that will work.
import streamlit as st
import requests
font_family = st.text_input("Font family:", value="Akronim")
r = requests.get(f"https://fonts.bunny.net/css?family={font_family}")
if r.status_code == 200:
st.markdown(
f"""
<style>
/* Insert CSS from fonts.bunny.net */
{r.text}
/* Use font for titles */
h1 {{
font-family: '{font_family}';
}}
</style>
""",
unsafe_allow_html=True,
)
else:
st.info("Font not found :(")
st.title("The quick brown fox jumps over the lazy dog.")
Edit: The code could be further reduced:
import streamlit as st
font_family = st.text_input("Font family:", value="Akronim")
st.html(
f"""
<style>
/* Import CSS from fonts.bunny.net */
@import url(https://fonts.bunny.net/css?family={font_family});
/* Use font for titles */
h1 {{
font-family: '{font_family}';
}}
</style>
"""
)
st.title("The quick brown fox jumps over the lazy dog.")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.