CSS issue with highlighting menu items

Recently delving into the world of HTML and CSS, I encountered a tricky issue with my menu.
The problem arises when hovering on an element - it should highlight by expanding padding and changing border color. However, for some reason, when I hover on one element, the other four elements shift downward inexplicably.
I've tried adjusting margins, paddings, and positions to troubleshoot this peculiar behavior.

nav #MotherList{
    list-style-type:none;
    margin:0px;
    padding:0px;
    text-align:center;
}
li.navoptions {
    width:103px;
    height:93px;
    padding:0px;
    border-radius:4px;
    margin-left:5px;
    margin-right:5px;
    position:relative;
    top:4px;
    color:black;
    text-align:center;
    background-color:red;
    display:inline-block;

}
.navoptions:hover{
    background-color:white;
    padding:2px;
    position:relative;
    top:2px;
    margin-left: 3px;
    margin-right: 3px;
}
.navoptions div {
    width:100px;
    height:90px;
    border-radius:4px;
    margin-left:auto;
    margin-right:auto;
    position: relative;
    top:1.5px;
    background-color:yellow;
    background-size:100px 90px;
    background-repeat: no-repeat;
    text-indent: -999999px;
}
#nav1{
    background-image:url("../images/nav1.png");
}
#nav2{
    background-image:url("../images/nav2.png");
}
#nav3{
    background-image:url("../images/nav3.png");
}
#nav4{
    background-image:url("../images/nav4.png");
}
#nav5{
    background-image:url("../images/nav5.png");
}
<header>
            <ul class="MainList">
                <li class="MainListMember"><a href="">Home</a></li>
                <li class="MainListMember"><a href="">Products</a></li>
                <li class="MainListMember" id="Dave" onclick="window.location.href='td.html'"><a href="td.html">Logo</a></li>  <!-- Broken <a href> -->
                <li class="MainListMember"><a href="">Contacts</a></li>
                <li class="MainListMember"><a href="">Infos</a></li>
            </ul>
        </header>
        <nav>
            <ul id="MotherList">
                <li class="navoptions"><div id="nav1">opt 1</div></li>
                <li class="navoptions"><div id="nav2">opt 2</div></li>
                <li class="navoptions"><div id="nav3">opt 3</div></li>
                <li class="navoptions"><div id="nav4">opt 4</div></li>
                <li class="navoptions"><div id="nav5">opt 5</div></li>
            </ul>
        </nav>

If you'd like to take a look at the project files, you can find them here.

There are some comments within the code, and some of them may need correction.

Answer №1

Are you in need of this information?
Please provide me with some details so I can update my response.

.navoptions:hover{
    background-color:white;
     border: 1px solid red;
     padding: 50px;
}
.navoptions  {
    width:100px;
    height:90px;
    float: left;
    border-radius:4px;
    margin-left:5px;
    margin-right:5px;
    position: relative;
    top:1.5px;
   border: 1px solid black;
    background-color:yellow;
    background-size:100px 90px;
    background-repeat: no-repeat;
    text-indent: -999999px;
}
#nav1{
    background-image:url("../images/nav1.png");
}
#nav2{
    background-image:url("../images/nav2.png");
}
#nav3{
    background-image:url("../images/nav3.png");
}
#nav4{
    background-image:url("../images/nav4.png");
}
#nav5{
    background-image:url("../images/nav5.png");
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
  <header>
    <ul class="MainList">
        <li class="MainListMember"><a href="">Home</a></li>
        <li class="MainListMember"><a href="">Products</a></li>
        <li class="MainListMember" id="Dave" onclick="window.location.href='td.html'"><a href="td.html">Logo</a></li>  <!-- Broken <a href> -->
        <li class="MainListMember"><a href="">Contacts</a></li>
        <li class="MainListMember"><a href="">Infos</a></li>
    </ul>
  </header>
  
        <div id="MotherList">
          <div class="navoptions" id="nav1"></div>
          <div class="navoptions" id="nav2"></div>
           <div class="navoptions" id="nav3"></div>
            <div class="navoptions" id="nav4"></div>
             <div class="navoptions" id="nav5"></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

Implementing Node.js with browser cache and handling 304 responses

I am currently in the process of creating a single page application with a standard HTML layout as shown below: <html> <head> <title>...</title> <link rel="stylesheet" media="all" type="text/css" href="css/main.css"> ...

Resizing and adaption of Div elements

There's a challenging issue I've been facing and I can't find a way around it. What I'm trying to achieve is a responsive design where both the menu and text resize seamlessly when the resolution changes or when there's a zoom in/ ...

Tips for retaining and showing previously inputted information in form fields

I have 2 forms on each page. Here is an example of one of them. $('form').submit(function(e) { e.preventDefault(); }) <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form action="" me ...

Bootstrap doesn't display in the dropdown menu

Struggling to get a dropdown menu to display on my page, my HTML code is: <div class="dropdown d-inline"> <div class="widget-header mr-3"> <button href="#" class="icon icon-sm rounded-circle border" data-toggle="dropdown"><i cl ...

Notify the user with a Jqgrid alert when they attempt to select multiple checkboxes

When editing rows, I wanted to avoid multiple selections. In order to achieve this, I need to check the condition if(count>1) and display an alert message. I am struggling to figure out how to retrieve the count of selected checkboxes in jqGrid. var m ...

Having difficulty setting a value for a tooltip with replaceWith() function

When using jQuery's .replaceWith() method to insert new DOM contents, I noticed that all content gets replaced except for the value of the title. Even though I tried different approaches, the tooltip only displays {{descriptions.title}} instead of the ...

Selecting parent class using JQuery

This is some HTML I have: <label class="rlabel">First Name</label> <input class="rinput" type="text" placeholder="Fisrt Name" required /> <label class="rlabel">Last Name</label> <input class="rinput" type="tex ...

Alter the style of a div by clicking on a button

Can the background image of a div be changed by selecting a button outside of the div? For example: HTML <div id="change"></div> <div id="buttons"> <button class="button1">this</button> <button class="button2"> ...

What sets the Name Attribute apart from the Name Token in HTML?

I was exploring the safety of using spaces in a name attribute and found varying opinions, with most agreeing that it is safe due to the Name attribute's utilization of CDATA token rather than a Name token. However, I am struggling to grasp the exact ...

Positioning Multi-level Drop Down Div in Javascript - How to do it efficiently?

I'm currently working on a horizontal menu using CSS and JavaScript with multiple levels. I've implemented a toggle function to show the submenu container, but it's causing the links below it to be pushed down. Is there a way to make the dis ...

"Embedding social content within an iframe may result in the element being unresponsive

I have a setup where I'm utilizing social embed to include Instagram content in the footer. When I insert the provided iframe code, the layout looks correct but the content is not clickable. <iframe src="https://embedsocial.com/facebook_album ...

Extract the content from the span element on Whatsapp Web

Currently, I am in the process of learning Python along with Selenium and have encountered a challenge. I am attempting to extract the username from the most recent message in a WhatsApp group conversation. Despite several attempts, I have been unsuccessfu ...

Having an excessive amount of CSS Sprites or none at all can be detrimental to your website's performance

UPDATE: Attempted to adjust the height to 27px as recommended by kennypu, but still facing issues. I am working with a sprite containing multiple icons that I want to extract for navigation purposes. Unfortunately, I'm struggling to properly display ...

Discover the perfect technique to employ insertString for effortlessly adding a new line onto a JEditorPane integrated with HTML functionality

Is there a difference between executing this code: conversationPane.setText(msg + conversationPane.getText()); and this code? conversationPane.setText(conversationPane.getText() + msg); I noticed that the second line does not display the message, but I ...

"What is the best way to display mathematical equations written in HTML within a Flutter

My HTML Text <p>hello</p> <div class="mathjax-equation"> \(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\) </div> I am interested in displaying this mathematical equation on a Flutter mob ...

Syntax error detected: Unexpected T_ELSEIF statement

I have been attempting some basic coding on codeacademy and struggling with an issue for the past hour. What could be causing this error to display: "Parse error: syntax error, unexpected T_ELSEIF on line 12 " <html> <head> <title&g ...

What is the best way to toggle the visibility of my menu using JavaScript?

I recently implemented a script to modify a CSS property in my nav bar as I scroll down, triggering the change after reaching 100px. $(window).scroll(function() { var scroll = $(window).scrollTop(); //console.log(scroll); if ...

Web Essentials is experiencing a problem with minified CSS

Today, while using Web Essentials 2013 for Update 3 with Visual Studio Express 2013 for Web, I encountered an issue with the minified CSS file. The website I am currently working on is built on a Twitter Bootstrap platform and utilizes two separate CSS fil ...

What is the best way to modify a CSS property using logical operators in JQuery?

If an element with the class ".has_padding" does not have any text content, it should be set to "display:none;". However, those elements with text inside should remain visible. Below is some code where I have styled the elements to demonstrate the issue. ...

Adjusting the Pace of a CSS Marquee

My CSS marquee effect is working perfectly, but I am having trouble with the speed. The issue arises when the text length varies - shorter text takes longer to scroll while longer text scrolls quickly. This inconsistency is due to the animation duration an ...