Adjustable spacing for elements located under a fixed navigation bar on small screens

My website has a navbar that increases in height for smaller window sizes due to the text logo wrapping. How can I adjust the padding dynamically for the jumbotron below, so it is not partially covered by the navbar when the text logo spans multiple lines? If you have a better solution, please let me know.

Relevant HTML:

<nav class="navbar navbar-expand-md navbar-light bg-light fixed-top">
  <div class="container-fluid">
    <a class="navbar-brand logo-text" href="./index.html">
            <span class="color-human">Logo Logo</span> <span class="color-education">Text Text</span> <span class="color-project">Snippet</span>
        </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto">
        <li class="nav-item active">
          <a class="nav-link active " href="#">Item 1 <span class="sr-only">(current)</span></a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Item 2</a>
      </ul>
    </div>
  </div>
</nav>
<div class="jumbotron feature">
  <div class="container">
    <h1>Some header</h1>
  </div>
</div>

CSS:

 .logo-text {
  white-space: normal;
}

body {
  padding-top: 3.5rem;
}

Check out this example on jsfiddle.net

Answer №1

According to this explanation, it is not possible to dynamically position an element below a position:fixed element using CSS. The navbar is essentially taken out of the DOM flow, causing other page elements like the jumbotron to be unaware of its size or position.

A potential solution could be to utilize position:sticky (Bootstrap's sticky-top) instead in order to mimic the fixed navbar effect. This way, there would be no need for padding adjustments...

<nav class="navbar navbar-expand-md navbar-light bg-light sticky-top">
  <div class="container-fluid">
    <a class="navbar-brand logo-text" href="./index.html">
            <span class="color-human">Logo Logo</span> <span class="color-education">Text Text</span> <span class="color-project">Snippet</span>
        </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      ...
    </div>
  </div>
</nav>
<div class="jumbotron feature">
  <div class="container">
    <h1>Some header</h1>
  </div>
</div>

https://www.codeply.com/go/EOH8sCCNnp

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

Ant Design: Incorporating margin and padding causes slight rendering glitches in the markup

https://i.sstatic.net/BWmFU.gif https://i.sstatic.net/ZaLH8.gif When I apply margin and padding to this class, it starts twitching like in the first GIF. Removing the margin and padding fixes the issue, but I need them for styling. What is causing this ...

When a jquery confirm dialog is displayed, the scroll bar mysteriously fades away

Whenever a jQuery confirm dialog is displayed, the scroll bar on the page disappears, causing the page to suddenly shift to the right. Here is the JavaScript code for the dialogue: <script src="vendor/jquery-confirm.min.js"></script> <link ...

Control your thumbnails with the powerful iDangerous Swiper feature

Are you new to coding? I'm looking for help on linking thumbnail images to a swiper so that when a thumbnail is clicked, it moves the swiper-container to the corresponding slide. Any ideas or suggestions would be greatly appreciated! Here's an e ...

Parameter within onClick function that includes a dot

I'm attempting to design a table that enables an onClick function for the Change Password column's items so my system administrator can adjust everyone's password. Each onClick triggers the "ChangePassOpen" function which opens a modal with ...

Timer Does Not Appear to be Counting Down

I recently added a countdown clock to my website, but I'm having an issue with it not updating in real-time unless the page is refreshed. I'm not very familiar with javascript, so I found some code online and made some modifications myself to sui ...

Registration form creation with file input type resulting in a database storing null values

When submitting my registration form, all entered values except the input type=file are being saved in the database. The file input returns a null value of "0" in the database, even though a file path is chosen from the desktop. I'm trying to figure o ...

Tips on increasing the click zone size without disturbing surrounding elements

Is there a way to make an inline element more clickable without affecting other elements? Adding padding helps, but it can disrupt the layout. I tried using negative margin to counteract the padding, but it produced some unexpected results: span { p ...

Empty the localStorage when terminating the IE process using the Task Manager

Utilizing HTML5 localStorage to keep track of my application session has been a useful feature. Here is a snippet of the code I am currently using: if(typeof(Storage)!=="undefined") { if(sessionStorage.lastname=="Smith") { alert("Your ses ...

Is it possible to retrieve event.data beyond the onMsg callback function in JS SSE?

My current project involves using three.js to display accelerometer data in real-time and in 3D on a web browser. To transfer data from the remote server to the client side, I am utilizing server-sent-events (SSE). While I have successfully implemented th ...

Having trouble with JavaScript not working when clicking an image and toggling a div?

Why isn't the onclick image and toggle div functionality working with JavaScript? I made the change from: <input type="button" id="Showdiv1" name="Showdiv1" value="Show Div 1" onclick="showDiv('div1')" /> to: <img src="https://d ...

Activate the use of sqlite HTML5 functionality within Firefox

Struggling to generate a database using HTML5 sqlite in Firefox and cannot seem to make it work. Unfortunately, it appears that Firefox does not support this feature. Is there any alternative method for using it in Firefox? I have tested the code on both ...

Getting two <div> elements to float below one another can be achieved by utilizing the CSS property "float

Can someone please tell me the trick to floating one element below another on the same side? I want them both to float but be positioned under each other. Thank you in advance. ...

What causes a semiopaque background to show through in an adjacent div?

My webpage consists of three elements. The main element is centered with a beautiful background image, while overlayed on top of it is a second div with a black semi-transparent background to enhance text readability. In addition, there is a floating div ...

Verify if there is a value in at least one of the multiple input fields

I have 4 input fields and I need to check if at least one of them has a value. If none of them are filled out, I want the function to stop. Below is the current code snippet I'm using but it's not working as expected because it doesn't ente ...

The presence of the target tag remains unchanged when a media query is used

Hello, I have a question regarding a specific issue in my code. I am trying to use a media query to make a tag disappear when the width of the window is less than 1200px, but it's not working as expected. I believe it might be related to inheritance. ...

What changes can be made to the code in order to prevent the Highcharts graph from overlapping with the fixed navigation bar located at the top of the page

I am looking to create a navigation bar that stays fixed at the top of the page. I followed the approach outlined on the w3schools website to achieve this. However, when I add a highchart javascript graph to the page, the fixed navigation bar stops workin ...

Ways to prevent a Div from shifting its position due to dynamic changes in height of another element

Looking for a solution regarding a 'bouncing loader' div that moves up and down in an infinite loop? Check out this jsfiddle However, the issue arises when I place a button below the loader, as it also moves in sync with the animation effect. I ...

Bony Scaffold - halting the motion of specific components

Currently, I am utilizing skeleton to create a fluid layout, which is functioning effectively for the most part. However, I have encountered an issue specifically with the 2 column layout on Magento at this URL: In this setup, the navigation on the left s ...

Stop horizontal scrolling when using connected lists in full-height columns with jQuery UI Sortable

I am in the process of developing a web application that features two full-height columns utilizing Flexbox in Bootstrap v4. Each column contains a sortable list that can be rearranged using jQuery UI Sortable. HTML: <div class="container-fluid h-100 ...

unable to properly display application.html.erb

I am encountering difficulties in rendering my application.html.erb template as I am receiving the following error message: ActionView::SyntaxErrorInTemplate within ApplicationController#home app/views/layouts/application.HTML.erb:10: syntax error, unexpec ...