The CSS code hides a portion of the fixed side navigation when the main content is shorter than the navigation bar

My side nav and main content are both dynamic. The issue arises when the navigation is longer than the main content, causing its height to be set to the viewport height and the rest is hidden. How can I address this problem without resorting to an unsightly scrollbar on the navigation?

I'm looking for a way to keep the navigation fixed in place.

section {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

nav {
  -webkit-box-flex: 0;
  -webkit-flex: 0 0 250px;
      -ms-flex: 0 0 250px;
          flex: 0 0 250px;
}
nav ul {
  position: fixed;
}

main {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
      -ms-flex: 1;
          flex: 1;
}
<section>

  <nav>
    <ul>
     <!-- Inserted shortened list here -->
      <li>51</li>
      <li>52</li>
      <li>53</li>
    </ul>
  </nav>

  <main>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur tenetur tempore voluptatum quasi architecto accusamus sapiente quaerat sequi ratione optio eos, accusantium corrupti dolor aliquid similique culpa libero officiis atque?</p>
  </main>

</section>

Answer №1

Dealing with a fixed position element can be challenging because it is taken out of the document flow, causing its height to be ignored.

One approach is to use absolute positioning for the navigation bar and then utilize a media query to switch to fixed positioning when the window size decreases.

Another option is to incorporate Javascript for this task.

Check out how others have tackled this issue:

  • Fixed sidebar too tall for browser (bottom getting cut off)
  • CSS: sidebar with fixed position being cut off
  • How to keep a fixed div taller than viewport attached to body
  • Challenges when fixing an element that exceeds browser window height

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

Codeigniter Autocomplete Feature with Ajax - Page Not Found Error

I am currently facing an issue while porting a working php application with AutoSuggest JS to CodeIgniter. My expertise in CI is not very strong which is why I ventured into this task. The problem lies in the fact that it is not functioning as expected. Be ...

I am seeking guidance on retrieving the value of a text box that is activated by a radio button through jquery within the provided code

When conducting my test case, the user is presented with a choice between ielts and toefl. If the user chooses ielts, an input box appears where they can enter their ielts score. My goal is to extract and store the value entered in that input box. Check ou ...

What is the best way to handle an AJAX parameter in CakePHP?

Currently, I am using a select2 plugin with ajax functionality. For more information about this plugin, you can visit: $("#UserCliente").select2({ placeholder: "Select a State", minimumInputLength: 3, ajax: { url: "../clients/listaclients/", dataType: ...

How can I simply show a specific value from an object in Vue?

I've created a Vue application that filters messages and displays them on a page. Currently, when a user selects a message from the list, the entire JSON data associated with that message is shown on the page. However, I want to only display a specifi ...

The combination of select2 and jsonform is not functioning properly

I am having trouble rendering multiple select2 with JSON form. $('#resource-form').jsonForm({ schema: { rest: { type: 'object', properties: { template_id: { type: "array", items: { ...

The Node.js azure-storage TableService does not offer any functionalities or operations

Having trouble connecting to my Azure storage account due to issues with the azure-storage module. Specifically, after creating a TableService object, I am only able to access the filter method on it. When attempting to use methods like queryTables and cre ...

Tips for showing variables in Console directly from the Sources panel?

As I dive into debugging front-end code in Chrome, I am encountering a question that may seem basic to experienced developers. Specifically, while exploring the Sources panel within Chrome's Dev Tools, I find myself hovering over a variable labeled _ ...

Seeking guidance on Ajax .... in need of clarification

Could someone provide an explanation for this code snippet: const greeting = 'hi'; $.ajax({ type: "POST", url: "check.php", data: "greeting="+greeting, success: function(response){ alert( "Response received from server: " + resp ...

The alternating colors in the sorting table are not visible due to the divs being hidden with the display set

I've come across a problem that has me stumped. So, there are two sorting filters on a table and one of them hides rows that don't apply, messing up the alternating colors. Take a look at the function that sorts and the CSS below. The issue is pr ...

Implementing a design aesthetic to installed React components

After downloading a react multiselect component created by an individual, I installed it using npm install .... and incorporated the component in my react code with <MultiSelect .../>. The dropdown checkbox 'menu' is designed to allow users ...

Implement a fadeout effect by using a timeout function that adds a class to the div element in

I implemented a loader on my webpage that animates for 3 seconds before a function kicks in to modify the styles and make it invisible. I am looking to add a fadeout effect when the 'waa' style is applied to the 'load' div. setTimeou ...

storing information between elements

Imagine I have a requirement to include a data provider element for my users, like this: <user-data-provider user-data="{{data}}"></user-data-provider> This element would send an ajax request to retrieve the logged in user's information. ...

Can sweetalert2 be used as a tooltip?

I have a query, is it feasible to include a tooltip in the alert message? Alternatively, could there be another tooltip option available? Swal.fire({ title: '<strong>An example with HTML tags</strong>', icon: 'info', ...

I am facing an issue where my Tailwind classes are not functioning properly when passed through props, but they work seamlessly when I directly link the Tailwind CSS using

//Button.jsx import React from 'react'; const Button = (props) => { let color = props.color || 'blue'; return ( <button className={`px-4 py-2 font-bold text-black bg-${color}-500 rounded-full hover:bg-${color}-700 focus ...

Send a bundle of data through AJAX requests

An issue has been encountered on an HTML/PHP page named sucessful.php where a variable job_id passed from another page is not being received by the destination page interview.php. The problem arises when attempting to transfer two variables and their corr ...

Simplify code by eliminating uuid references

Greetings! I am currently working with some code that is generated within a JSP tag and utilizes the jQuery data function to connect data with a div element. In order to link the jQuery script with the div on the webpage, I have employed a UUID. However, ...

How to achieve striped columns with Bootstrap 4.0 instead of striped rows

Here is how my table currently looks with the implementation in place: https://i.sstatic.net/b7onC.png Since my data is displayed vertically, I am interested in adding stripes to the columns or implementing some CSS hovering effect when the mouse is over ...

Customize request / retrieve document cookies

I have successfully implemented a cookie in my express/node.js application. var express = require('express'); var cookieParser = require('cookie-parser') var app = express(); app.use(cookieParser()) app.use(function (req, res, next) ...

How can I assign a variable from a function that may include an ajax request?

I have created my custom script for loading content via AJAX if it hasn't already been loaded. Check it out below: /* * Custom Content Loader */ var loaded_urls = {}; function fetch_content_from_url(url) { if (loaded_urls[url] === undefin ...

develop a hidden and organized drop-down menu using the <select> tag

I am currently developing a website for a soccer league. The site includes two dropdown lists with specific criteria, where the options in the second dropdown are limited based on the selection made in the first dropdown. My goal is to initially hide cer ...