Ensure that divs remain in a static position within the dialog box

Within the jQueryUI dialog, I have gray boxes at the top and bottom of the visible area represented by the .nav elements. I want these gray boxes to stay fixed in their position even when scrolling within the dialog. Despite setting position: absolute, the gray boxes still scroll with the content. How can I achieve a fixed position for them inside the dialog?

$(document).ready(function() {
var opts = {
  modal: true,
    height:300,
  };
  
  $('#wrapper').dialog(opts);
  $('#wrapper').dialog('open');

});
.images {
  z-index: 1;
}

.image {
  display: inline-block;
  border: 1px solid black;
  width: 100%;
  height: 500px;
}

.nav {
  width: 90%;
  height: 30px;
  z-index: 2;
  background-color: rgba(192, 192, 192, 0.7);
  position: absolute;
}

.top {
  top: 0px;
}

.bottom {
  bottom: 0px;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

<div id='wrapper'>
  <div class='top nav'>
  </div>

  <div class='bottom nav'>
  </div>

  <div class='images'>
    <div class='image'>
    </div>

    <div class='image'>
    </div>

    <div class='image'>
    </div>
  </div>

</div>

Answer №1

To properly position the top navigation, add the following inline style to your wrapper element and adjust the top property:

<div id='wrapper' style='position: static;'>

Additionally, include the following CSS code:

.top {
  top: 45px;
}

$(document).ready(function() {
var opts = {
  modal: true,
    height:300,
  };
  
  $('#wrapper').dialog(opts);
  $('#wrapper').dialog('open');

});
.images {
  z-index: 1;
}

.image {
  display: inline-block;
  border: 1px solid black;
  width: 100%;
  height: 500px;
}

.nav {
  width: 90%;
  height: 30px;
  z-index: 2;
  background-color: rgba(192, 192, 192, 0.7);
  position: absolute;
}

.top {
  top: 45px;
}

.bottom {
  bottom: 0px;
}
<link href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>

<div id='wrapper' style='position: static'>
  <div class='top nav'>
  </div>

  <div class='bottom nav'>
  </div>

  <div class='images'>
    <div class='image'>
    </div>

    <div class='image'>
    </div>

    <div class='image'>
    </div>
  </div>

</div>

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

Concurrent HTTP Requests - AngularJS

My directive, known as machineForm, includes a dataService: dataService.getMachineTaxesById($scope.machineId).then(function (response) { $scope.machine.machineTaxes = response.data; }); I am using this directive twice simultaneously. <div class= ...

Retrieve data from MongoDB using the find() method results in an empty response, however,

While working on a project to practice my MongoDB skills, I encountered an issue with retrieving all the data from MongoDB. Despite receiving a successful 200 response, I was unable to properly extract all the data. Using Express framework for this task, ...

Shortcut in JavaScript for verifying a specific key-value within an array of objects

As an angular developer, I have limited knowledge of JavaScript shorthand methods. I recently encountered a situation where I needed to loop through an array using a for loop in JavaScript. Let's say I have an array of Objects like: var arr = [{nam ...

Is the output of MongoDB's ISODate() function always distinct from that of the Date()

After reviewing the documentation, my understanding was that ISODate simply wrapped the Date constructor. However, I've encountered issues when working with dates very far in the past. For example: new Date(-8640000000000000); ...

Modify the CSS to update the navbar's active color

I'm currently using a simple CSS top navbar (without Bootstrap or any other framework) and I want to be able to change the active page's button color. For example, when I navigate to the home page, I want the button in the navbar to turn red or a ...

Transfer chosen item from real-time ajax search to input box

Looking to implement a live search feature similar to Google's on my website. The idea is to copy the selected live search results and display them in a textbox named "oki" using AJAX. The data for the live search is fetched from an XML file. Below ...

Obtain data using a jQuery AJAX request

Below is the original code snippet: var result = null; $.post('test.php', 'q=testdata', function(response) { result = response; }); I have a requirement to utilize result in my code, either during or immediately after the ajax requ ...

The nth-child selector is not functioning correctly with material-ui components

Trying to figure out how to give two paragraphs different background colors using nth-child. Here's the JSX: <div className={classes.paragraphs}> <p>Test 1</p> <p>Test 2</p> </div> And the CSS: const useSty ...

Design a custom scrolling navigation bar for enhanced user experience

Struggling with web design as I develop a site in ASP.NET. I have a database full of courses, each with numerous modules. The challenge is creating a navigation bar that dynamically adjusts to accommodate the varying number of modules per course without o ...

Error Loading Message Appears with jQuery Mobile 1.3.1 and Flot Integration

I am trying to implement a flot interactive example with jQuery Mobile 1.3.1 in my project. However, I am encountering an issue with the latest version of jQuery Mobile where there is a strange frame around the chart and a "loading" text at the bottom of t ...

Fill in a data table beginning with the column next to the first

My issue involves a datatable retrieving JSON data from an API. The table is configured so that the first column should only display a checkbox. However, upon data retrieval, the first column gets populated as well. https://i.sstatic.net/izb5B.png $.getJ ...

Issues detected between Angular and Express rendering operations

Having an issue with my angular code. It runs perfectly on its own, but when I try to access it on localhost with express, it only displays the HTML file. Here's my server code: var express = require('express'), app = express(); app ...

Adjust the position if the height exceeds 100 pixels

Can someone help with this code issue? $(document).ready(function () { if ($('.pi-img').height() > 100) { $(this).css('top' , '30%'); console.log('yeah'); } }); I am encountering difficu ...

The browser is not displaying the results from Mongodb, yet they are appearing in the console

I am currently using the following code for my router: let mongoose = require('mongoose'); // connecting with our model let ByProduct = require('../models/Byproduct') router.get('/',(req,res,next)=>{ ByProduct.find().th ...

How to send a contact form in Wordpress with multiple attachments via email without using any plugins

The main objective is to enable users to submit their own content for new articles (including text and files) to the administrator's email. A form has been created for this purpose: <form class="form form-send" enctype="multipart/fo ...

Is there a way to figure out the number of days from the current date using jQuery UI datepicker?

Hello there, I'm currently facing an issue with calculating the number of days from the present to a chosen date after utilizing a jQuery datepicker. It seems that the date formatting is getting altered upon selection, causing discrepancies in the ca ...

Illuminate the rows in a table generated from a parsed text file using PHP

I am facing an issue with my PHP logic for selecting and highlighting rows in a table based on dropdown selection. I have a group of text files that are parsed into a table, and I need to highlight rows that match selections from 5 dropdowns created from t ...

How to insert an image into a placeholder in an .hbs Ember template file

I'm looking to enhance a .hbs template file in ember by incorporating an image. I am not a developer, but I'm attempting to customize the basic todo list app. <section class='todoapp'> <header id='header'> & ...

Mobile Drag and Drop with JavaScript

While experimenting with a user interface I created, I utilized jQuery UI's draggable, droppable, and sortable features. However, I observed that the drag and drop functionality does not work in mobile browsers. It seems like events are triggered diff ...

Javascript: Dynamically Altering Images and Text

One feature on my website is a translation script. However, I'm struggling to activate it and update the image and text based on the selected language. This is the code snippet I am currently using: <div class="btn-group"> <button type ...