The Bootstrap menu does not seem to be affecting the positioning of the body text

I recently came across an issue with a Bootstrap-based site I'm working on.

When I click the hamburger menu on mobile view, the main content doesn't shift down to accommodate it, causing an overlap. Not ideal :-(

Here's my Demo: https://jsfiddle.net/8kvgoxw3/

Does anyone have suggestions on how to fix this?

@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

body {
  margin: 0px;
}

img {
  max-width:100%
}
h1, .navbar-collapse ul li a, p, .nav-tabs > li > h2 > a, h2, h3, h4 {
  font-weight: 300!important
}

h3 {
  border-bottom:1px solid white;
  margin-top:10px;
  margin-bottom:0px;
  padding-bottom:10px
}

h3 a, h3 a:hover {
  color:white;
  cursor:pointer;
}

h4 {
  margin-bottom:0;
}

h5 {
  font-size:16px;
  font-weight:bold;
  color:#fff;
  margin-bottom:15px;
}

.item div div {    
  border-bottom: 1px solid grey;
  padding-bottom: 5px;
}

/* Custom, iPhone Retina */
.cbp-af-header {
  position: fixed;
  top: 0;
  left: 0;
  transition: all 0.4s ease;
}
.cbp-af-header img{
  transition: all 0.4s ease;
}

.cbp-af-inner {
  transition: all 0.4s ease;
}

.cbp-af-header{
  -webkit-animation-name:fadeInDown;
  -webkit-animation-direction:normal;
  -webkit-animation-play-state:running;
  -webkit-animation-fill-mode:forwards;
  -moz-animation-name:anim_titles;
  -moz-animation-direction:normal;
  -moz-animation-play-state:running;
  -moz-animation-fill-mode:forwards;
  -webkit-animation-iteration-count:1;
  -moz-animation-iteration-count:1;
  -webkit-animation-duration:.5s;
  -moz-animation-duration:.5s;
  -webkit-animation-delay:0s;
  -moz-animation-delay:0s;
  -webkit-animation-timing-function:ease-out;
  -moz-animation-timing-function:ease-out;
}

.cbp-af-header .cbp-af-inner img {
  margin: 20px 0;
}

.cbp-af-header.cbp-af-header-shrink .cbp-af-inner img {
  margin: 10px 0;
}
.cbp-af-header.cbp-af-header-shrink {
  height: 160px;
}

.cbp-af-header {
  height: 355px;
}

.cbp-af-header.cbp-af-header-shrink img {
  margin-top: 10px;
  transition: all 0.5s ease 0s;
  width: 42%;
  height:unset;
}

button {
  background:black!important;
  z-index:99999999;
  position:relative;
}

.container.body-text {
  margin-top: 140px; 
}

.nav {
  background:blue
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

<div class="container">
  <nav class="navbar">
    <div class="row">
      <div class="col-md-12">
        <div>
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <div class="center-block text-center" style="text-align:center">
            <div class="cbp-af-header">
              <div class="cbp-af-inner">
                <img src="http://placehold.it/600x200" alt="logo">
                <div id="navbar" class="collapse navbar-collapse">
                  <ul class="nav navbar-nav">                                                                                                  <li class=" menu-item menu-item-type-post_type menu-item-object-page menu-item-14"><a href="/test/">Test</a>
                    </li>
                    <li class=" menu-item menu-item-type-post_type menu-item-object-page menu-item-14"><a href="/test/">Test</a></li>
                    <li class=" menu-item menu-item-type-post_type menu-item-object-page menu-item-14"><a href="/test/">Test</a?</li>
                 </ul>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </nav>
</div>
<div class="container body-text">
  <div class="page">
    <div class="text-center">
      <h1 style="line-height:28px">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus dolor et velit sodales, a pretium metus finibus. Vivamus lacinia a ligula vitae volutpat. Curabitur nulla lectus, aliquam ac massa at, lacinia mattis odio. Vivamus vitae orci urna. In iaculis sem a eleifend sollicitudin. Curabitur varius, felis vel efficitur condimentum, sapien est condimentum nibh, convallis faucibus sem tortor a purus. Aenean consequat nec diam quis aliquam. Aenean laoreet felis ac tincidunt iaculis. Quisque eu ipsum eget tortor sodales vehicula. Mauris sem lacus, tincidunt id sem id, posuere mollis velit. Nam enim magna, vulputate id eleifend eu, consectetur vel leo.</p>
    </div>
  </div>
</div>

Answer №1

To ensure your header stays in place, it should have a fixed position so it doesn't push content down. You can achieve this using the following CSS:

.cbp-af-header {
        position: fixed;
        top: 0;
        left: 0;
          transition: all 0.4s ease;
    }
    .cbp-af-header img{
      transition: all 0.4s ease;
    } 

If you're experiencing issues, consider removing the fixed positioning.

Answer №2

To properly position the content, consider using margin-top to push it down to the desired location. Ensure mobile compatibility by testing on different devices. If the content still does not move as expected, try adding the !important directive.

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

Interactive Canvas Feature: Drag and Drop Across Various Objects in HTML 5

I have developed a custom code that enables the creation and rendering of objects on an HTML5 canvas. class Rectangle extends Shape { constructor(options, canvas, type = 'rectangle') { super(...); // inherited from the super class thi ...

What is the AngularJS equivalent of prevAll() and nextAll() functions in jQuery?

Currently, I am working on a project that involves AngularJS and I'm having trouble finding an example that fits my needs... With AngularJS, I know how to apply a class when an element is clicked, but how can I add a class to all previous items and r ...

Only reveal a single div when hovering

I am currently working on a project that involves utilizing the Wikipedia API to allow users to search for and retrieve information from Wikipedia. I have made significant progress, but I have encountered an issue. When hovering over the "each-list" div, t ...

JS receiving a reference to an undefined variable from Flask

I referenced this helpful post on Stack Overflow to transfer data from Flask to a JS file. Flask: @app.route('/') def home(): content = "Hello" return render_template('index.html', content=content) HTML <head> ...

Straightforward JSON issue

I am new to JSON and I need to work with it now. I have tried several examples from the jQuery page, but they don't seem to be working for me. I have a *.php file that generates a string. From what I understand, this is how I pass JSON data from PHP ...

Shifting an HTML anchor to account for a stationary header - Safari compatibility with alternative CSS styling

I made adjustments to my HTML anchors by adding an offset in the CSS to accommodate for a fixed header in my theme: margin-top: -175px; padding-top: 175px; } /* Adjustments for screen sizes of 760px and smaller */ @media (max-width:760px){ #r ...

The modal is not displayed when the on click listener is triggered

I'm a beginner in the world of programming and I'm currently working on creating modals that pop up when clicked. However, I'm facing an issue where the pop-up message doesn't appear when I click the button. Oddly enough, only the overl ...

Different custom background images for every individual page in Nuxt

Looking for a unique background-image for each page in my app is proving to be challenging. Currently, I have defined the background-image in style/app.scss. @import 'variables'; @import 'page_transition'; @import url('https://f ...

Are there methods to create a link that will open an application if it is already installed, or a website if it is not?

Similar Question: How can I check if a URL scheme is supported in JavaScript on iPhone Safari? Let's say my application is called "exapp" and I want to create a link on a website that can open the application if it is installed. If the user agen ...

Guide to implementing jQuery autocomplete with an AJAX request to a PHP file

I'm currently working on implementing a jQuery autocomplete feature, and here is the code I have so far: $( "#text" ).autocomplete({ source: function( request, response ) { $.ajax({ type: 'GET', url: ' ...

Navigate with ease using the Jquery tabbar feature

I am currently troubleshooting a jQuery tabbar navigation that is almost working as expected. Here are the issues I've encountered: 1. Upon page load, no article appears visible. 2. When I click on a different tabbar item after the initial selection, ...

Steps to shorten HTML content while maintaining consistent column width

Is there a way to ensure that the fixed column width is maintained even with long strings? I am trying to display a report in a jsp by having headers in one table and content in another table, both with columns set to the same width. However, some of the ...

Height of border not being displayed accurately

I have been searching for a solution to my unique issue with inserting borders in HTML and CSS. When I try to add a border to three images, the height does not display correctly. This is all part of my learning process to improve my skills in coding. Belo ...

Is there a method to view text options that are too long within a fixed width <select multiple> HTML box?

Here is the code I am working with: <div id='div2' style='height: 430px; width: 350px; overflow:auto;'> <select multiple id="id" size="28" style="FONT-SIZE: 12px; FONT-FAMILY: Arial; width: 100%"> It's a challenge bec ...

The scroll-to-top arrow remains concealed when the height of the html and body elements is set to 100

I recently added a scroll-to-top arrow using Jquery, and it's functioning flawlessly. However, I encountered an issue when I set body and html to a height of 100%, as it mysteriously disappears. View this fiddle for reference The HTML structure is a ...

The Kendo element's DataSource becomes null if accessed outside of a function

There is an issue with the behavior of Kendo MultiSelect's dataSource that I have noticed. When I trigger a function through an event on an element, such as a button click: function fillForm() { var ms = $("#selector").data('kendoMultiSelec ...

Complete my search input by utilizing ajax

It's only been 30 minutes since my last post, but I feel like I'm making progress with my search posts input: I've developed a model that resembles this: function matchPosts($keyword) { $this->db->get('posts'); ...

Adjusting the tab size and space size to their default settings within VSCode

I'm currently facing an issue with my VSCode setup. I am trying to configure the space size to be equal to 1 and tab size to be equal to 2 as the default for every project. However, despite my efforts, it keeps reverting back to spaces: 4 for each new ...

JQuery Ajax encounters a 500 error message due to an internal server issue

I'm currently using the jQuery library to send an ajax request to a PHP file. Initially, everything was working perfectly fine with a relative path like this: url:"fetch_term_grades.php", However, when I modified the path to be more specific like th ...

Possible revised text: "Exploring methods for verifying elements within a div using Selenium

I have a situation where I need to verify elements within a div by using the following xpaths. The xpath for each item is as follows: Item 1:- //*[@id='huc-last-upsell-rows']/div[1]/div[2]/div[1]/div/div/a/img Item 2:- //*[@id='huc-last-u ...