The hovering of the mouse over a dropdown menu causes a division on the page to shift

Creating a website with a dropdown menu and slider division can be tricky. When hovering over the menu, the submenu displays but causes the slider division to shift down.

Does anyone have suggestions on how to fix this issue? Below is the code:

<html>
<head>
<style type="text/css">
#header{
    height: 90px;
}
#navigation{
    height: 30px;
    background-color: #0099FF;
    border: 1px solid #0099FF;
    border-radius: 10px;
    z-index:1000;
}
ul {
    list-style: none;
    padding: 0px;
    margin: 0px;
}
ul li {
    display: block;
    position: relative;
    float: left;
    padding-right: 40px;    
}
li ul {
    display: none;
}
ul li a {
    display: block;
    padding: 5px 10px 5px 10px;
    text-decoration: none;
    color: #FFFFFF;
    font:Verdana, Arial, Helvetica, sans-serif;
    font-size: 20px;
}
ul li a:hover {
    background: #00CCFF;
}
li:hover ul {
    display: block;
    z-index: 1000;
}
li:hover li {
    float: none;
}
li:hover a {
    background: #00CCFF;
}
li:hover li a:hover {
    background: #D2F5FF;
}
#drop-nav li ul li {
    border-top: 0px;
}
#clearmenu{
    clear: left;
}
#sliderandnews{
    height: 300px;
}
#slidermain{
    height: 300px;
    width: 65%;
    float: left;
}
#news{
    height: 300px;
    width: 33%;
    border: 2px solid #F0FFFF;
    border-radius: 20px;
    float: right;
    background-color: #F0FFFF;
}
.clear{
    height: 40px;
}
</style>
</head>
<body>
<div id="header">
</div>
<div id="navigation">
    <ul id="drop-nav">
        <li><a href="#">Home</a></li>
        <li><a href="#">About Us</a></li>
        <li><a href="#">Academic Programs</a>
            <ul>
                <li><a href="#">BBA</a></li>
                <li><a href="#">BCA</a></li>
                <li><a href="#">BE</a></li>
            </ul>
        </li>
        <li><a href="#">Faculties</a></li>
        <li><a href="#">Admission</a></li>
        <li><a href="#">Downloads</a></li>
        <li><a href="#">Contact</a></li>
    </ul>
</div>
</div>
    <div class="clear"></div>
    <div id="sliderandnews">
        <div id="slidermain">
            This section is changes its position on mousehover
        </div>
        <div id="news">
        </div>
    </div>          
</body>
</html>

Answer №1

One issue is that your elements have relative positioning, causing them to shift down when the submenu appears. To fix this, you can use absolute positioning on the navigation bar and set its distance from the top using the CSS top property. This eliminates the need for the #header element (which only provides a top margin).

#navigation{
    position:absolute;
    top:90px;
}

A similar approach can be taken with the #sliderandnews block. Since the navigation menu has absolute positioning, it's no longer part of the HTML flow within the page. As a result, you'll need to add an appropriate top margin to this element.

#sliderandnews{
    height: 300px;
    margin-top:190px;
}

Check out the updated solution on this fiddle.

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

Having trouble aligning elements in a single line using Bootstrap

I've been experimenting with different methods to align elements on the same line, such as using bootstrap and flexbox. However, I haven't been able to achieve the desired result. The goal is for the elements to stay on the same line even when th ...

Utilize ng-checked in AngularJS to bind all values from an array to checkboxes

I'm working on a project where I need to bind the name and age of a person using checkboxes, with the data looped through ng-repeat. However, I seem to be able to only get the "name" from the array, not the "age". Can someone please help me find my mi ...

Tips for Aligning Images of Various Sizes in the Center of a div

My images are displayed in a horizontal line, but some have different sizes. I want to center all the images within their container div for a better look. Is there a way to do this automatically with CSS so that the images remain centered regardless of siz ...

Only apply the CSS filter alpha to the parent element and not its children

I am working on implementing an alert message box using HTML and CSS. Below is the code I have so far: <div class="dim" id="msg"> <div class="dialog_wrapper"> <div class="dialog" id="msg_value"></div> ...

Styling Challenges with CSS/AngularJS Accordion in Footer

I want to create a page layout as shown below: +---------------------------+ | Auto-fill / v scrollable ^| | || | || | v| +---------------------------+ | Fixed [][][] ...

Issues with Collapse Feature on Bootstrap 3 Navbar

I need your help with a problem I'm facing. The navigation bar is not collapsing when I click the link in mobile view. Check out this video for more details: https://www.youtube.com/watch?v=2dBpcFMjqY0 ...

The mouse pointer adjusts according to the event

I am working on an ajax request and I have implemented a feature where the cursor changes appearance. document.body.style.cursor = "wait"; This immediately shows the cursor as a spinning circle when the request starts. At the end of the request, I ch ...

Struggling to make the DataTables.net Bootstrap 5 example function properly

I'm currently working on familiarizing myself with the styling example for Datatables.net using Bootstrap 5, which can be found at https://datatables.net/examples/styling/bootstrap5.html. I've followed the code provided in the example closely, bu ...

Elements missing from the Bootstrap 5 framework

I've been attempting to link my bootstrap card deck to a mongo database with ejs. The website renders without any errors, but for some reason, the cards are not displaying. Does anyone have any insight into what could be causing this issue? Below is ...

Searching for the name of dynamically generated input fields using jQuery

I have a straightforward form featuring radio buttons <form> <input type="radio" name="radio_1" value="1" />Radio 1 <input type="radio" name="radio_1" value="2" />Radio 2 <input type="radio" name="radio_1" value="3" />Radio 3 </ ...

Hide the div element once the timer runs out

Struggling to make a timer disappear when it reaches 00:00, every attempt results in the div being hidden immediately. Check out the code snippet I've been working with: $(document).ready(function(e) { var $worked = $("#worked"); function upd ...

Animate with ease upon mouse entry into the div

I have a question about hovering. $(".hover li img").mouseenter(function() { $(".overlay").animate({ left: pixels+"px" }); }); The overlay class is a transparent box around the image, with a red border. I want the border to move when hov ...

Tips for getting free jqgrid to display frozen column borders in the search toolbar

If the actions column has a caption of "Activity" or custom settings and is frozen, the free jqgrid will not display column borders for this column in the search toolbar. Vertical lines do not appear in the search toolbar: Is there a way to resolve this ...

Maintain a fixed element and enable the rest of the elements to scroll as the mobile browser address bar collapses while scrolling upwards

Currently facing a challenge where I want the background image to remain static while the address bar and content underneath scroll up. The image occupies 90% of the view height, and although I've prevented it from resizing and jumping when the addres ...

Block entry to HTML files unless the user has logged in utilizing PHP sessions

I have been working on implementing a verification process to check if a user is logged in when accessing a specific HTML file. When a user tries to access something.html without being logged in, I would like to redirect them to index.php and restrict acc ...

Learning the process of extracting Fast Fourier Transform (FFT) data from an audio tag within

I am struggling to retrieve the FFT data from an <audio> tag without any syntax errors. After reviewing the Web Audio API documentation, I have written a sample code snippet as follows: <audio id="aud" controls="controls" src="test.mp3"></a ...

Why is JSP compilation essential in achieving its goals?

At the moment, I am involved in modifying JSP and subsequently uploading it to the server for compilation. Upon compilation, a .class file is generated for the modified JSP. If I were to remove the original JSP from the server, would it still function pr ...

Enhancing a class's properties from its parent component using React

Recently, I decided to dive into React by taking on the challenge of rebuilding the Google Weather app. My main objective is to have the main section update whenever a day is selected. Initially, I believed that updating the props within handleSelectionAt( ...

Using AJAX to upload an image and passing multiple parameters

I'm facing an issue when trying to upload an image along with other input text in a form and send it to ajax_php_file.php. Whenever I upload the image, all my input text fields appear empty. Any assistance would be greatly appreciated. Thank you very ...

The peculiar formatting issue with the jQuery datepicker that arises when adding more months

When adjusting the numberOfMonths parameter to a higher value such as 6, I noticed that the datepicker display appears unusual with the background extending further than expected. Take a look at my demonstration on jsfiddle: http://jsfiddle.net/zw3z2vjh/ ...