Issue with the height of sections in the active menu

While the set-up below is functional for content within section height limits, it fails when exceeding the limit causing overflow.

Adding "display: table" or "overflow: hidden" to fix the overflow issue affects the menu's active state behavior.

Setting sections' heights to auto instead of 100% results in overlapping sections and disrupts the layout.

I urgently need help as the entire project layout hinges on resolving this issue.

Any suggestions are greatly appreciated. Thank you.

JSFiddle

HTML

<header>
    <nav>
        <ul>
            <li><a class="link active" href="#section_one">Section One</a>
            </li>
            <li><a class="link" href="#section_two">Section Two</a>
            </li>
            <li><a class="link" href="#section_three">Section Three</a>
            </li>
            <li><a class="link" href="#section_four">Section Four</a>
            </li>
        </ul>
    </nav>
</header>

... (Additional HTML code)

CSS

* {
    margin: 0;
    padding: 0;
    border: 0px none;
    font-family: "Calibri", sans-serif;
    font-weight: 700;
    font-size: 16px;
    vertical-align: top;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
}
... (CSS codes)

JavaScript

// Script for Header scroll compensation and smooth scrolling

$(document).ready(function () {
    $(window).scroll(function () {

        var y = $(this).scrollTop();

        $('.link').each(function (event) {
            if (y >= $($(this).attr('href')).offset().top - 40) {
                $('.link').not(this).removeClass('active');
                $(this).addClass('active');
            }
        });

    });
});

$(function () {
    $('a[href*=#]:not([href=#])').click(function () {
        if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
            var target = $(this.hash);
            target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
            if (target.length) {
                $('html,body').animate({
                    scrollTop: (target.offset().top - 40)
                }, 850);
                return false;
            }
        }
    });
});

Answer №1

Another option is to apply CSS to correct the floating elements without modifying the existing HTML structure.

.wrapper:after {
    display: table;
    content: "";
    clear: both;
}

Answer №2

To solve the problem, make sure to clear your floats. Simply add this line of code at the end of your section:

<br style="clear: both" />

Check out this updated version that works correctly in all browsers: JSFiddle


The original fiddle was not functioning properly in Internet Explorer. By changing '40' to '39' on one specific line, the issue was resolved in IE:

scrollTop: (target.offset().top - 39)

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

How can JavaScript be used to make an AJAX request to a server-side function?

I am diving into the world of AJAX and feeling a bit uncertain about how to structure my AJAX call. $.ajax({ type: "POST", url: "Default.aspx/function", data: '{ searchBy: id }', contentType: "application/json; charset=utf-8" }). ...

Determining the value of an element by examining the clicked element

My goal is to determine the remaining balance in my cart based on the selected item. Let's say I have 3 items in my cart, and I choose one that costs $100. Previously, I stated that I had a total of $300. In my HTML code, there are elements with IDs ...

php file unable to retrieve ajax data parameter

As a JAVA developer exploring php development, I encountered an issue while trying to retrieve the value of currMonth in a php file that is passed as a parameter in a .js file. Despite my efforts, my log is outputting everything except for the information ...

Compatibility of $.post with .on("mouseenter") event handlers

In my code, I have a few $.post functions that are currently working. The one I'm trying to implement now is: $("#rbody").on("mouseenter", ".date, .quarter", function(e) { $.post("classinfo.php", { id: $("td").attr("value"); ...

Fixed width blocks automatically adjusting to small containers

When I try to add text to my absolute block inner div, it doesn't expand as expected. I am aware that expanding within a parent container with a specified width, such as <div class="main_wrap"></div>, can be problematic. Unfortunately, I ...

Determining the Location of a Drag and Drop Item

I have been utilizing the code found at for implementing Drag & Drop functionality. My inquiry is: How can I retrieve the exact position (x,y) of a group once it has been dragged and dropped? ...

Tips for placing a large image within a small div

I have an image with a ratio of 1920*1300 that I want to be displayed on any device the website is viewed and cover the entire div. Check out my code below: .carousel { width: 100vw; height: 80vh; position: relative; } .carousel a { width: 1 ...

Issue with JavaScript-generated dropdown menu malfunctioning in WebView on Android devices

During my testing of the app on a Galaxy Tab with Android 2.2, I encountered an issue within the WebView component. The problem arises when I have a local HTML page generated dynamically and it contains a SELECT element like this: <select class='d ...

Exploring Angularjs: Navigating to a particular element within ng-repeat

I created a custom directive that generates a list of buttons using ng-repeat: HTML <div ng-controller="toggleButtonController" ng-init="init()" id="parent"> <div ng-repeat="btn in setting" style="display:inline"> <button class ...

Issue encountered when attempting to utilize multiple datasets with Twitter Typeahead/Bloodhound

Hello, I am currently learning how to use Typeahead and Bloodhound with the latest javascript. Below is a snippet of my code: Html: <div id="multiple-datasets"> <input class="typeahead" type="text" placeholder="NBA and NHL teams"> </div ...

Issue with Ajax not triggering PHP script

My first experience with using Ajax to call a php script is not going well. The script doesn't seem to be working at all. Here is the snippet of code where I implemented Ajax: <?php if (isset($_GET['error'])) { switch ($_GET[ ...

Having trouble with your jQuery learning and not seeing any results?

I have been attempting to utilize jQuery for a project, but unfortunately, nothing seems to be happening when I click the button. Despite my various attempts to modify the code, the desired effect still eludes me. I am specifically using Firefox as my bro ...

Retrieving data from an XML file using an Ajax request

I am using a native AJAX request to insert node values into HTML divs. However, I have noticed that when I update the XML values and upload them to the server while the website is running, Chrome and IE do not immediately reflect the changes (even after re ...

Why does the socket.io output only appear after I refresh the page?

Feeling stuck and seeking guidance. After following tutorials, I was able to develop a basic user registration/login app in nodejs/express with the addition of a socket.io chat feature. Upon user login, they are directed to the real-time chat page where i ...

What could be the reason my view is not rendering after calling my action through Ajax?

I am encountering an issue with my Ajax call that is hitting the controller action 'SearchFromWithin'. The problem I am facing is that the view does not get displayed when the call is made. Although I can enter the view and step through it, the s ...

What is the best way to set up multiple unique uglify tasks in grunt?

I am facing issues when trying to create multiple Uglify tasks in Grunt. Currently, I have to toggle between commenting and uncommenting a task to get it to work properly. I need assistance in generating two separate minified .js files using this plugin ...

How to incorporate a JavaScript variable into an ERB tag

Exploring the integration of a JavaScript variable within erb <% %> tags has led me to consider using AJAX (refer to How to pass a javascript variable into a erb code in a js view?). As someone new to JavaScript and AJAX, it would be extremely helpfu ...

Automatically create CSS properties for left and top using absolute positioning

When looking at these websites as models: On each of them, I noticed that there is a well-organized column of boxes for every post. I attempted to recreate this using various methods, but couldn't achieve the exact layout on my own website. It seems ...

Reading properties of undefined in React is not possible. The log method only functions on objects

I'm currently facing an issue while developing a weather website using the weatherapi. When I try to access properties deeper than the initial object of location, like the city name, it throws an error saying "cannot read properties of undefined." Int ...

What are the steps for effectively utilizing the EmChart to achieve precise font sizes in ems?

Can you explain the intended use of this chart and instructions for how to utilize it? ...