An image that is in motion at an inappropriate time

My website has run into an issue. Within the navigation bar, there are two unordered lists containing list items and nested ul tags with images in some of the list items. When applying animations, the image moves along with the tabs. Here are visual examples of the problem:

Image stays in place when not interacted with

Hovering over the lock causes the image to move right and reveal a logout button

Dragging down results in the image following the movement

The issue persists across interactions

The code snippet for the entire navigation bar is provided below:

body{
      margin-left: 10px;
      padding: 10px;
      font-family: arial;
      background-color: #E9EBEE !important;
    }

    nav {
        margin-top: -10px;
        height: 80px;
        background-color: #2A3943;
        ...
    

I have attempted using 'position: absolute;' and 'position: fixed;', but no positive outcome was achieved. Any assistance in resolving this issue would be greatly appreciated.

//Kevin

Answer №1

Your code needed a complete overhaul as it was disorganized and didn't follow standards. Take a look at the revised code below to see where you can improve your CSS skills.

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
    * {font-family: arial;}
    header {background-color: #2A3943;padding: 10px 40px;box-shadow: 2.5px 2.5px 2.5px #888888;border-radius: 4px;}
    header nav h1 {display: inline-block;color: white;}
    header nav {display: block;}
    header nav ul {list-style: none; padding: 0;display: block;}
    header nav ul li {position:relative;display: inline-block;border-radius: 2px;cursor: pointer;padding: 22px;background-color: #1AB188;box-shadow: 2.5px 2.5px 2.5px #0d1215;margin:0 5px;text-align: center;}
    header nav ul li:hover > ul {visibility: visible;transform: translateY(0%);transition-delay: 0s, 0s, 0.3s;opacity: 1}
    header nav ul li > ul {background-color:#1AB188;top:60px;visibility: hidden;position: absolute;width: 100%;transform: translateY(-2em);transition: all 0.3s ease-in-out 0s, visibility 0s linear 0.3s, z-index 0s linear 0.01s;left:0;opacity: 0;}
    header nav ul li a {text-decoration: none;color: white;display: block;}
    header nav ul li a:hover {color: #333;}
    header nav ul li:last-child {float: right;margin-right: 0;padding: 20px 0; background: none;box-shadow: none;}
    header nav ul li:first-child {border-radius: none;padding: 0;background-color:transparent;box-shadow: none;margin-right: 40px;}
    header nav ul li:nth-child(2) {margin-left: 0;}
    header nav ul li:last-child > * {display: inline-block;vertical-align: middle;}
    header nav ul li:last-child img {margin-right: 20px;width: 40px;}
    header nav ul li:last-child:hover a button {visibility: visible;transform: translateX(0);transition-delay: 0s, 0s, 0.3s;opacity: 1}
    header nav ul li a button {padding: 5px;cursor: pointer;background-color: rgba(164, 19, 34, 0);color: #fff;visibility: hidden;transform: translateX(2em);transition: all 0.3s ease-in-out 0s, visibility 0s linear 0.3s;opacity: 0;}
    header nav ul li > ul li {box-shadow: none;background: none;display: block;border-radius: 0;margin:0;padding: 21px !important}
    header nav ul li > ul li:last-child {float: none;}
    header nav ul li > ul li:first-child {margin: 0;}
</style>
</head>
<body>
<div class="wrapper">
<header>
    <nav>

        <ul>
            <li><h1>MemeStagram</h1></li>
            <li><a href="index.php" title="Home">Home</a></li>
            <li><a href="memes.php" title="Memes">Memes</a>
                <ul>
                    <li><a href="most-popular.php" title="Most Popular">Most Popular</a></li><br>
                    <li><a href="newest.php" title="Newest">Newest</a></li>
                    <li><a href="most-viewed.php" title="Most Viewed">Most Viewed</a></li>
                </ul>
            </li>
            <li><a href="about.php" title="About Us">About Us</a></li>
            <li><a href="contact.php" target="Contact">Contact</a>
                <ul>
                    <li><a href="bebin.php" title="Bebin">Bebin</a></li>
                    <li><a href="balbin.php" title="Balbin">Balbin</a></li>
                    <li><a href="bohan.php" title="Bohan">Bohan</a></li>
                    <li><a href="barcus.php" title="Barcus">Barcus</a></li>
                    <li><a href="bonis.php" title="Bonis">Bonis</a></li>
                </ul>
            </li>
            <li><a href="settings.php" title="Settings">Settings</a></li>
            <li class="login"><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f4/Simpleicons_Interface_unlocked-padlock.svg/1024px-Simpleicons_Interface_unlocked-padlock.svg.png" alt="Login/Logout"><a href="logout.php" title="logout"><button type="submit">Logout</button></a></li>
        </ul>
    </nav>
</header>
</div>
</body>
</html>

Since you're new to CSS, here's an explanation of some selectors used:

> This selector targets elements directly inside another element, like li > ul.
* Selects all elements on the page, in this case setting their font to Arial.
:hover Applies styles when the element is hovered over.
:last-child Targets the last child of a parent element.
:first-child Targets the first child of a parent element.

Here's a working example on CodePen: https://codepen.io/anon/pen/MrPBEW

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

Centering an image on a webpage using CSS

Here is the code I am using for displaying my image: return <div class="imgContainer"><img src={broomAndText} alt="broomAndText" /></div> In my css file, I have included the following styling: .imgContainer { tex ...

What is the best way to arrange list items in this manner?

I am facing challenges with aligning elements properly on the navigation bar. I would like the words (home, players, about, contact) to be vertically centered in relation to the heart logo. Here is how it currently appears: This is how I want it to look ...

Having difficulty comprehending the syntax of Linear Gradients

Seeking assistance on understanding how background images and linear gradients function together. Currently, I am only seeing a solid color instead of the intended image. Can someone please explain how this code is supposed to work? background-image:lin ...

jQuery, trigger a function when the document has finished loading

I have created the following code in an attempt to display a message to only Internet Explorer users visiting the page: <script src="jquery.reject.js"></script> <script> $(document).ready(function() { $.reject({ reject: { a ...

Setting the height and width of a table and utilizing rowspans may not produce the desired outcome

I've encountered an issue with my table that I can't seem to resolve. The CSS should dictate the width and height, but something seems off. Am I approaching this incorrectly or is there something missing? Also, why are the borders not aligning p ...

Why Isn't AJAX Displaying the Output from PHP?

Currently, I am implementing ajax to display a string received from a php file. This particular php file is generating rows for an html table. My goal is to have ajax place these rows within a with a specific id that resides inside a and I want this oper ...

Utilize React JS to incorporate multiple instances of the Bootstrap carousel within a webpage using Reactstrap

I am having difficulty using the bootstrap carousel multiple times on a single page. I have attempted to copy it as a new item numerous times, but I keep encountering errors. <CarouselItem onExiting={() => setAnimating(true)} onExited={() => ...

The CSS outline properties vary between input elements and input elements in focus

I'm encountering an issue with a box and its associated CSS outline style. When the box is focused, it should display a blue outline (which is working fine). However, upon form validation, if there is an error, the .error class is added which should c ...

Verify if the button is assigned a specific class, then generate a 'completed' div

I'm new to working with Jquery and I have a question. In my upload form, when something is uploaded the upload-button changes class from: <a class="upload-button upload buy" id="upload-button"><span>Upload a document</span></a> ...

Unable to conceal the scrollbar while keeping the div scrollable

I've been attempting to implement the techniques outlined in the guides on this site, but I'm encountering difficulty hiding the scroll bar while still maintaining scrolling functionality! My current approach involves setting the parent as relat ...

What is the best way to adjust a fixed-width table to completely fill the width of a smartphone browser?

In an ancient web application, the design was primarily constructed using rigid tables: <div class="main"> <table width="520" border="0" cellspacing="0" cellpadding="0"> <tr> <td>...</td> </ ...

Unable to remove the initial item from my shopping cart

Currently working on my computing science assignment and decided to create an online store. I followed a tutorial to implement the shopping cart functionality, but I'm facing an issue. I can delete every item in the cart except for the first one that ...

Learn how to apply inline styles to multiple objects within a single element using React

In my project using React, I am attempting to apply styles only to a specific element within another element. Here is an example with an h1 tag: const Header = () => { const firstName = "Ashraf"; const lastName = "Fathi"; const date = new Date() ...

How to use image source and mouse hover effects in CSS3

Can we create a CSS3 class for the src, onmouseout, and onmousehover properties? <img src="http://www.example.com//images/pic.png" onmouseout="this.src = 'http://www.example.com/images/pic.png'" onmouseover="this.src = 'http://www.examp ...

Is there a way to align this in a horizontal inline block?

I have this element and I would like it to display inline-block but horizontally. Currently, it is displaying as inline-block but vertically. Here is my HTML: <div class="ondisplay"> <div class="left-text"> <p&g ...

Change the JavaFX ToggleButton's color and revert back to its original color

Can you tell me what the default background and border color is for a toggle button? Here’s an example of code that changes the background color of a toggle button: i.toggle11.setOnAction(e->{ if(i.toggle11.isSelected()){ i.toggle ...

Error: Incorrect data input in Django calendar form

I have a DateForm class defined in my form.py file: class DateForm(forms.Form): date = forms.DateTimeField( input_formats=['%m/%d/%Y %H:%M'], widget=forms.DateTimeInput(attrs={ 'class': 'form-control dateti ...

When I use .fadeToggle, my div transitions smoothly between visible and hidden states

Looking to create a sleek navigation menu that showcases a colored square when hovered over? I'm currently experiencing an issue where the squares are not aligning correctly with the items being hovered. Switching the position to absolute would likely ...

Building modals with Bootstrap

Currently, my website is built using Bootstrap, JQuery, HTML, and CSS. I am looking to enhance the user experience by incorporating a modal output feature. The idea is that when a user clicks on a specific hyperlink, a modal window will open displaying t ...

Need to update various form fields at once with jquery?

There is a form with fields for firstname, lastname, email, country, along with edit icon and submit/cancel buttons. When the user clicks on the edit icon in the top right corner, all values will be displayed in textboxes and the country will be shown in ...