The .fixed-top navbar in Bootstrap conceals various elements behind it

Hey there, I'm hoping you're doing well. I've run into a little issue with Bootstrap that I was hoping to get some help with. According to the Bootstrap documentation, it seems like .sticky-top may not be supported by some browsers anymore. So, I switched to using .fixed-top instead. However, when I apply this class, I notice that part of the body content gets hidden behind the navbar. I'm wondering if there's a different way to address this problem, or if the only solution would be to add a margin-top in the CSS. The .pt-5 class doesn't quite cut it in revealing the content properly. Thanks a bunch for any assistance you can provide.

:root {
  --body-font: "Roboto Mono", monospace;
  --main-font: "Caveat", cursive;
  --secondary-font: "Dosis", sans-serif;
  --primary-color: salmon;
  --secondary-color: rgb(71, 66, 65)
  --box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

.navbar-brand {
  font-family: var(--main-font);
  font-size: 22px !important;
}

.text-secondary{
  color: rgb(94, 94, 94);

}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <meta name="description" content="I'm Marizabelle Aldana, 27yo developer based in Guatemala, currently living in London.">

    <title>Marizabelle's website - Homepage</title>

    <link rel="stylesheet" href="src/styles.css" />

    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Amatic+SC&family=Anton&family=Caveat:wght@600&family=Dosis:wght@700&family=Roboto+Mono:wght@200&display=swap"
      rel="stylesheet"
    />

    <!-- CSS only -->
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3"
      crossorigin="anonymous"
    />

        <script
      src="https://cdn.jsdelivr.net/npm/bootstrap/dist/js/bootstrap.bundle.min.js"
      integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
      crossorigin="anonymous"
    ></script>

  <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
  </head>
  <body>
      <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
      <div class="container">
        <a class="navbar-brand text-secondary" href="index.html">Home</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 text-secondary" href="about.html"
                >About me</a
              >
            </li>
                <li class="nav-item">
                  <a class="nav-link text-secondary" href="project.html">Projects</a>
                </li>
            <li class="nav-item">
              <a class="nav-link text-secondary" href="about.html#email">Contact me</a>
            </li>
          </ul>
        </div>
      </div>
    </nav>

    <div class="jumbotron jumbotron-fluid">
  <div class="container">
    <h1 class="display-4">Fluid jumbotron</h1>
    <p class="lead">This is a modified jumbotron that occupies the entire horizontal space of its parent.</p>
  </div>
</div>

    <div id="greeting">
      <img
        id="cat-icon"
        class="rounded mx-auto d-block pt-5"
        src="https://img.icons8.com/external-tulpahn-flat-tulpahn/64/000000/external-happy-cat-emoji-tulpahn-flat-tulpahn.png"
      />
      <br />
      <div class="sentence text-center">
        Hi
      </div>
    </div>
    </body>

Answer №1

To optimize the layout, consider including padding-top for the main content to accommodate the fixed navbar's height. Review the adjustments I implemented below.

I specifically applied a fixed height to .jumbotron for scroll testing purposes.

:root {
  --body-font: "Roboto Mono", monospace;
  --main-font: "Caveat", cursive;
  --secondary-font: "Dosis", sans-serif;
  --primary-color: salmon;
  --secondary-color: rgb(71, 66, 65) --box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}

.navbar-brand {
  font-family: var(--main-font);
  font-size: 22px !important;
}

.text-secondary {
  color: rgb(94, 94, 94);
}

.jumbotron {
  height: 3000px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <meta name="description" content="I'm Marizabelle Aldana, 27yo developer based in Guatemala, currently living in London.">

  <title>Marizabelle's website - Homepage</title>

  <link rel="stylesheet" href="src/styles.css" />

  <link rel="preconnect" href="https://fonts.googleapis.com" />
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  <link rel="preconnect" href="https://fonts.googleapis.com" />
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  <link href="https://fonts.googleapis.com/css2?family=Amatic+SC&family=Anton&family=Caveat:wght@600&family=Dosis:wght@700&family=Roboto+Mono:wght@200&display=swap" rel="stylesheet" />

  <!-- CSS only -->
  <link href="https://cdn.jsdelivr.net/npm/--unique-hash--/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />

  <script src="https://cdn.jsdelivr.net/npm/--unique-hash--/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>

  <link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
</head>

<body>
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
    <div class="container">
      <a class="navbar-brand text-secondary" href="index.html">Home</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 text-secondary" href="about.html">About me</a
              >
            </li>
                <li class="nav-item">
                  <a class="nav-link text-secondary" href="project.html">Projects</a>
          </li>
          <li class="nav-item">
            <a class="nav-link text-secondary" href="about.html#email">Contact me</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>
  <section style="padding-top: 4em;">
    <div class="jumbotron jumbotron-fluid position-relative">
      <div class="container">
        <h1 class="display-4">Fluid jumbotron</h1>
        <p class="lead">This is a modified jumbotron that occupies the entire horizontal space of its parent.</p>
      </div>
    </div>

    <div id="greeting">
      <img id="cat-icon" class="rounded mx-auto d-block pt-5" src="https://img.icons8.com/external-tulpahn-flat-tulpahn/64/000000/external-happy-cat-emoji-tulpahn-flat-tulpahn.png" />
      <br />
      <div class="sentence text-center">
        Hi
      </div>
    </div>
  </section>
</body>

Answer №2

Make sure to include the following style in your index.css file for the body element: padding-top: 70px;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Setting up automatic CSS linting in a Vue.js project for seamless correction

Is there a way to enforce linting on the <style> segment within a .vue file while coding? I have set up eslint (with airbnb ruleset)+prettier for the <template> and <script> sections, which includes some auto-correction upon saving, but I ...

Arranging information within the Ngb-Accordion

Welcome to the code snippet showcasing how to create an accordion in Angular: <ngb-accordion [closeOthers]="false" activeIds="0"> <ng-container class="card" *ngFor="let post of Posts"> <ngb-panel title="{{post.title}} - ...

Connect ng-models with checkboxes in input field

I am facing an issue with binding ng-models using ng-repeat in an input checkbox tag. Let me share my code and elaborate further. app/main.html: <div ng-repeat="feature in features"> <input type="checkbox" ng-model="features[$index].name"> ...

Unexpected behavior with animation duration in Safari

We have a project in the works that involves CSS animation. Our goal is to update the animation duration using JavaScript. Although this change is effective in most browsers, it seems to have trouble with Safari and iOS. Below is the code we are using to ...

What is the most efficient method to use JavaScript to conceal unnecessary options?

I'm working with an HTML select element that has multiple options, and I need to be able to hide and show specific options as needed. Here's an example of my HTML code: <select> <option value="0">A</option> <option value="1" ...

Remove a data entry from the MySQL database by selecting the corresponding row in the table and utilizing the DELETE function

Is there a way to remove a record from my MySQL database by clicking on a row in a table that is generated using ejs? Below is the code I am currently using to generate the table rows. <% res.forEach(function(item){ %> <tr> ...

Widget for navigating through Youtube videos

I am currently working on creating a widget that allows users to navigate a YouTube video using buttons. For instance, if the video is of a car race, there would be buttons labeled Lap 1, Lap 2, and so forth. My idea involves adding an extension to the vi ...

Refine the search outcomes by specifying a group criteria

I have a scenario where I need to filter out service users from the search list if they are already part of a group in another table. There are two tables that come into play - 'group-user' which contains groupId and serviceUserId, and 'gro ...

Circular gradient backdrop

Looking to create a sleek and professional body background for my website that is as attractive as Twitter's. Can you help me achieve the same blue shaded background effect? I'm new to web development and would appreciate any guidance on how to m ...

Convert Soundcloud thumbnail into a printable format using the @media print CSS rule

For those wanting to add an embedded Soundcloud player on a blog: <iframe width="500" height="300" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/271188615&color=%23ff5500&auto_p ...

Using a variable as a URL parameter in a jQuery ajax request: tips and tricks

$.ajax({ type:"POST", url:"hostname/projfolder/webservice.php?callback=statusReturn&content="+str_table, contentType: "application/json; charset=utf-8", crossDomain:true, dataType:'jsonp', succe ...

What is the best way to save text in a selenium test script in order to display the total number of search results discovered on various search engines?

I'm currently tackling an assignment in my web applications testing class that involves creating a test script to evaluate the functionality of a search engine and then capturing and displaying the number of search results. The search bar that I' ...

The appearance of Google charts' X-axis leaves something to be desired

I used the google charts API to create a chart, but I am facing an issue with the X-axis labels. When I have multiple strings on the X-axis, the labels do not look good. I suspect that the problem lies in the X column type being a string instead of DATETIM ...

Mastering the art of transitioning between DIV elements

I am looking to implement a rotating three-card display on click, and have come up with the following code: $('.box1').click(function(){ $('.box1').toggleClass('removeanimate'); $(this).toggleClass('go'); ...

What is the best way to integrate a CSS designed flag in my website's top navigation bar?

My goal is to make my website multilingual, allowing users to switch between languages using flags in a dropdown menu. Initially, I tried creating the flag images solely with CSS for better resizing ability but faced difficulties. So, I resorted to using s ...

Styling the large drop-down menu for Internet Explorer 7

Check out the code snippet at http://jsfiddle.net/jN5G4/1/ Is there a way to align the drop-down menu for "5 Columns" to match the alignment of the other drop-downs? After removing the <a href...> </a> tags from the 5 Columns list item, the d ...

Flexbox: Distribute remaining space evenly while allowing content to wrap

Is there a method to instruct flexbox items to occupy the available space while wrapping as soon as they become smaller than their content? However, some items have a fixed width percentage. HTML <div class="grid"> <div class="grid__item"> ...

What is the process for creating a three-dimensional Bezier curve using JavaScript, specifically with three.js and WebGL?

I have a good grasp on creating a simple bezier curve, but I am curious about how to transform the curve into 3D. Additionally, I am wondering if it is possible to plot multiple curves to form an image like a cone. Any advice or guidance on this matter wou ...

How can I use CSS in Next.js to style a child element when its parent is being hovered over?

Here is the CSS code that specifically targets the child element "#overlay" when its parent, ".collection", is being hovered over: .collection { position: relative; overflow: hidden; } .collection:hover #overlay { position: absolute; opa ...

Issue with Bootstrap 4 list items not displaying in block format

Based on the information from , using li tags as block elements should result in a vertical menu. However, with Bootstrap 4, when I use li tags, the menu stays horizontal on toggle for small devices. Is this the expected behavior? <ul class="nav navb ...