Nav-Bar disappears using fixed-top argument

I am using the following code just to test out how can I add Navigation bar into the streamlit app:-

import streamlit as st
from PIL import Image
from streamlit_option_menu import option_menu

st.set_page_config(layout="wide")

col1,col2 = st.columns((2,3))


st.markdown('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">', unsafe_allow_html=True)

nav_bar = """
<nav class="navbar navbar-expand-lg bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Eventer</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About Us</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Contact</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Join</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
"""
st.markdown(nav_bar,unsafe_allow_html=True)

# Short description of the app
st.markdown("<h2 style='text-align: center; color: Black;'>Some title</h2>", unsafe_allow_html=True)
# some body
st.write("""

	This is some sample text.
	""")

Whenever I change the :
<nav class="navbar navbar-expand-lg bg-light">
to
<nav class="navbar fixed-top navbar-expand-lg bg-light">

The navigation bar disappears. Can someone point me where I am going wrong. I have never tried doing this with streamlit and am generally new to streamlit too.

1 Like

I run into a similar problem with Streamlit v1.10 with multipage support. Try adding z-index style to your first line.

1 Like

Python==3.9.0
streamlit==1.11.0

Streamlit header element z-index value is 999990,so it will cover your navbar,set it to 0.

import streamlit as st

st.set_page_config(layout="wide")

col1, col2 = st.columns((2, 3))

st.markdown(
    '<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">',
    unsafe_allow_html=True)

nav_bar = """
<nav class="navbar fixed-top navbar-expand-lg bg-light">
  <div class="container-fluid">
    <a class="navbar-brand" href="#">Eventer</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link active" aria-current="page" href="#">Home</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About Us</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Contact</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Join</a>
        </li>
      </ul>
    </div>
  </div>
</nav>
"""
st.markdown(nav_bar, unsafe_allow_html=True)

# Short description of the app
st.markdown("<h2 style='text-align: center; color: Black;'>Some title</h2>", unsafe_allow_html=True)
# some body
st.write("""

	This is some sample text.
	""")

# set streamlit header z-index
st.markdown('''
<style>
.stApp header {
    z-index: 0;
}
</style>
''', unsafe_allow_html=True)

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.