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.")