The navigation drawer is revealed when you drag down other elements on the webpage

When the navigation drawer opens, it pulls down other web blocks. When it closes, the blocks come up. Additionally, the drawer menu has occupied more space on the top of my website, making it difficult to keep blocks near the navigation bar. There is a large empty space there. However, the drawer menu works fine. How can I solve this issue?

HTML

<html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>My Web</title>
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">
            
        <header>
             <i id="hamburger" class="fa fa-bars"></i>
             <h2>MY WEB</h2>
        </header>

        <nav>
            <a href="#"><i class="fa fa-user-secret"></i><span>A</span></a>
            <a href="#"><i class="fa fa-check-circle-o"></i><span>B</span></a>
            <a href="#"><i class="fa fa-lightbulb-o"></i><span>C</span></a>
            <a href="#"><i class="fa fa-id-badge"></i><span>D</span></a>
            <a href="#"><i class="fa fa-lightbulb-o"></i><span>E</span></a>
            <a href="#"><i class="fa fa-lightbulb-o"></i><span>F</span></a>
        </nav>>
                
        <p><span style="font-size: 14pt"><p style="text-align: justify">   .... (content continues) ... </p></span>
         </p>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js">. 
        </script>
        
        </body>
    </html>
    

CSS


        header, nav {
            background-color: #06C;
            font-family: 'Open Sans';
        }
        
        /* additional CSS rules */
          
    

Javascript


        $("#hamburger").click(function(){
              $("nav").toggleClass('open', 'close');
          });
              
        $("a").click(function(){
              $("nav").toggleClass('open', 'close');
          });
    

Answer №1

To easily position your header and navigation, apply absolute positioning along with the following CSS code:

header {
position:absolute;
top:0;left:0;
}

nav {
position:absolute;
top:80px /* accounting for the header height */
left:0;
}

You can further organize your text elements by wrapping them in a div like this:

<div class="text-c">
   <!-- text elements -->
</div>

Then, use the following CSS code:

.text-c {
  margin-top:150px;
}

Check out a working example on CodePen here

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

When the browser is refreshed, jQuery will automatically scroll the window down

I created a div that matches the height and width of the window to simulate a "home screen." When scrolling down to view the content, everything works fine. However, after refreshing the browser, it automatically scrolls back to where you were before. I wa ...

Direct your attention solely on the input fields and buttons

Is it possible to restrict focus to specific elements, such as input fields and buttons? For example, if a user is focused on an input field and then clicks somewhere else on the page, the input field should retain focus. But if the user clicks on another ...

The mobile device isn't compatible with Jquery's "read more" feature

Recently, I've encountered some difficulties with the code below. It functions perfectly on desktop but fails to display correctly on mobile devices, showing the entire text instead. Take a look at the HTML section of the code: <span class="more" ...

Converting HLS streams with FFMPEG in ASP.NET Core 5.0 MVC

Overview I am currently developing a media streaming server using ASP.net Core REST Server, utilizing .NET 5.0 and ASP.net Core MVC. What I'm Looking For I require the ability to dynamically reduce the resolution of the original video file, such as ...

Can I use Ems instead of pixels for Chrome developer tools?

In all my style-sheets, I opt for using ems instead of px. However, in Chrome Developer Tools, the computed styles/metrics always display in px, even for elements where I specifically used ems: (Here is a screenshot of the computed lengths for a button wi ...

"An issue with preventing default behavior when clicking on a jQuery element

I need some assistance preventing a JQuery onclick function from scrolling the page to the top. I have tried using preventDefault() without success. You can find the code on this website: Below is the code snippet that I am currently using: $( document ...

Unable to dismiss my DIALOG component using onClick in REACT

Hey there! I'm feeling a bit frustrated trying to work with the DIALOG component in Material UI. My goal is to make a simple DIALOG component appear when I click on a bin Icon from the MUI library. Here's what I've tried so far: Setting ...

How can the hover event in jQuery be interrupted and cancelled during its execution?

Currently, I have implemented a jQuery hover event that causes an element to transition from 0.7 opacity to 1 when hovered over, and then revert back when the mouse moves away. However, one issue arises when the mouse accidentally passes over the element m ...

The SOAP request did not return an array with strings as expected, but rather an empty array, when

Encountered a situation where sending a SOAP request with an array of strings through Ajax results in the request being successfully passed to the web service. However, upon deserialization, the array is rendered empty. The ASP.Net WebService features the ...

Setting the maximum width in TinyMce

I have encountered an issue with TinyMce involving tables. When a user inserts a table that is larger than the main body layout, it causes the layout to become misaligned. Therefore, I am seeking the best solution to restrict users from inserting a table ...

Is there a way to determine if a user has already been timed out in Discord?

I'm in the process of developing a custom timeout command for my bot, as I believe it may offer greater functionality than the pre-existing feature. However, I am encountering an issue with determining whether a user is currently timed out or not. It ...

Exploring Mixed Type Arrays Initialization in Typescript using Class-Transformer Library

In my class, I have a property member that is of type array. Each item in the array can be of various types such as MetaViewDatalinked or MetaViewContainer, as shown below class MetaViewContainer{ children: (MetaViewDatalinked | MetaViewContainer)[]; ...

Retrieving FormData using ajax and passing it to aspx.cs code

After adding a debugger in the console, I am receiving confirmation that the file has been uploaded successfully. However, the debugger is not reaching the code behind, or in other words, the code behind is not accessible. This is the JavaScript file: fun ...

The function did not receive the parameter when ng-submit was executed

I created a function called reset(username) to log whatever is entered into the input field with ng-model="username". However, I am not seeing anything in the console. Why is that happening? Here is my function: $scope.reset = function (username) { co ...

When implementing fancybox within bxslider, numerous thumbnails are shown simultaneously

My issue arises when using fancybox within bxslider. Once I open an image, multiple thumbnails start repeating themselves endlessly. This problem only started occurring after adding bxslider. Any thoughts on why this might be happening? ...

The carousel is having trouble aligning the images div to the center

Struggling to create a carousel slide that automatically resizes image, but can't seem to get the inner div containing the images to center within the outer div. Even after trying various CSS properties like text-align:center and margin-left: auto, th ...

What is the method for applying an event to multiple elements using a jQuery selector?

Imagine a scenario where the markup looks like this: <ul> <li class="one"></li> <li class="one"></li> <li class="one"></li> </ul> Now, with the following jQuery script for an onclick function: ...

Placing a pin on the map: AngularJS

Struggling to grasp AngularJS and its mapping capabilities has been quite challenging for me. Currently, my code looks like this: <map data-ng-model="mymapdetail" zoom="11" center="{{item.coordinates}}" style="heigth:375px"> <div ...

How to change a CSS 'left' property using Jquery or Javascript

Upon examining my DOM, I found the following element: <div id="itemEditor" class="quoteItemEditorView partType_MATERIAL editMode selectorEnabled" style="left: -1px; right: 0px; width: auto; min-width: 480px; display: block;" > I have b ...

submitting a POST request with JSON payload including an array

Resolved. To solve this issue, you need to set the contentType to 'application/json' and use JSON.stringify(obj) instead of obj. However, keep in mind that you may need to adjust how you retrieve the data on your server, depending on the language ...