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

Ways to apply distinct styles to various ids and common classes

When dealing with multiple IDs such as id1, id2, and id3 that share common classes like .selectize-input and .select-dropdown, it can become cumbersome to set styles individually for each ID. Instead of writing: #id1 .selectize-input, #id2 .selectize-inp ...

Having difficulty locating the identification number of an item within the HTML coding

I'm currently trying to locate the ID of the "proceed to checkout" button for a bot that I am developing for my mother on the Best Buy website. However, it seems like the button's ID is hidden and I'm unable to determine how to uncover it. A ...

Stop material button from animating when clicked

On my webpage, I have created a unique button structure using Angular Material design: <button mat-button class="library-tile-button"> <button mat-button class="edit-library-button"> <img class="edit-library-img" src="..."/> ...

``There seems to be an issue with the alignment and vertical placement in both Firefox and IE

I'm currently working on a responsive landing page for a company and running into an issue with the CTA button's position outside of Chrome. It's functioning perfectly in Chrome, resizing as intended: Here is the CSS responsible for this: ...

How to enable the Copy to Clipboard feature for multiple buttons and transition from using an ID to a class identifier

Can someone please assist me? I have a copy to clipboard function that works well for IDs and a single button on my website. However, I need to modify it to work for multiple buttons and values with a class identifier. Unfortunately, I am unsure how to mak ...

Angular 2 partial static routing parameters with customizable features

Can an angular 2 routing configuration include a partial-static parameter? Currently, I am using a classic parameter setup like this: const routes: Routes = [ { path: ':type/fine.html', pathMatch: 'full', redirectTo: &ap ...

Using blending modes with gradient colors in an SVG design

I'm struggling to get my logo to change colors upon scrolling into a button with similar gradient colors, but I just can't seem to make it work. Can anyone lend me a hand? Thank you! Take a look at my Logo. I've attempted to add some styles ...

I am looking to save the session value into the search box of the appTables application by utilizing jQuery

Is there a way to save the session value in the search box of appTables by using jQuery? <?php $session = \Config\Services::session(); ?> <script type="text/javascript"> $(document).ready(function () { var searc ...

Troubleshooting: Difficulty with jQuery's resize event handler not functioning properly with

I'm currently facing an issue where I want a divider to adjust its size when another divider changes size due to new content being loaded into it. However, even after binding the resize event handler to the divider that loads the content, the event do ...

Creating a table with a tableHead cell comprised of multiple components in ReactJS/CSS using Material UI

It's possible that the title lacks description. I am attempting to generate a table with a specific layout like this Essentially, the "Average" cell is combined with two smaller cells for "height" and "width," which can be subdivided further. Unfortu ...

Struggling to send form data to the database

I've been working on sending form data to a database but for some reason, the data doesn't seem to be showing up when I check the database. Can anyone help me figure out what I'm doing wrong? I followed a tutorial on YouTube pretty closely, ...

Increase the spacing between the scrollbar and the border

Looking to create some breathing room between the scrollbar and the right border of my text area. I've tried adjusting the margin-right/left values in -webkit-scrollbar with no success. Here's my style component: const FormTextArea = styled.texta ...

How can I showcase images stored in an array using JavaScript?

I am currently developing a role-playing game (RPG). In order to enhance the gameplay experience, I am trying to implement a for loop that will dynamically generate buttons on the screen. Here is the code snippet I have created so far: $(document).ready(f ...

The best method for quickly loading a webpage that is over 20MB in size

My website is a single-page calendar featuring a full year's worth of images. With 344 requests and a total load size of 20MB, the page consists of a simple PHP script without a database. The requests include a CSS file (15KB), 4 JS files (20KB), two ...

What is the best way to divide a string into an array containing both linked and non-linked elements?

I'm struggling to find the right solution to my problem. I need to create a view that is enclosed in a clickable div. The content will consist of plain text mixed with clickable URLs - the issue arises when clicking on a link also triggers the method ...

Is there a more efficient method for showcasing model objects in Thymeleaf rather than utilizing a form?

I've been exploring Spring Boot, Thymeleaf, and frontend development in general. Currently, I have a frontend table that displays a list of objects from the backend, along with a form to allow users to view properties of each item in the list. Howeve ...

Retrieving the selected value from a dropdown menu without having to click on a

I'm facing an issue with 2 dropdown menus outside of an HTML table that is generated by PHP code. There's a submit button within this table, and here's how it's set up: <!doctype html> Select Year: ...

Adding plain HTML using jQuery can be done using the `.after()` and `.before()` methods

I have encountered a situation where I need to insert closing tags before an HTML element and then reopen it with the proper tags. The code snippet I am using is as follows: tag.before("</div></div>"); and then re-open it by adding proper tag ...

Activating/Deactivating a button with just a press

In my SQL data display, each row has an "Add To Zip" button that is initially enabled. I want to disable the button in the current row when it's clicked and later re-enable them using a different PHP file. What's the best way to achieve this with ...

What distinctions are there between placing a `<link rel="stylesheet" href=..video.scss>` in the index.html versus utilizing `import '../video.scss'`?

As a newcomer to React.js, I've observed that there are different ways to include stylesheets in a React Component. Some developers use the import method like this: import '../../styles/video.scss while others prefer to link the stylesheet dire ...