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

Using JQuery to modify several background images in unison

I have a CSS code that uses 8 images to create a frame: background-image: url(images/blue/tl.png), url(images/blue/tr.png), url(images/blue/bl.png), url(images/blue/br.png), url(images/blue/t.png),url(images/blue/b.png),url(images/blue/l.png),url(images/b ...

What is the best way to input keys without losing focus?

I am facing an issue with an HTML <input> field that displays autocomplete suggestions while the user is typing. I want to create an automated test using Selenium, where the driver inputs keys and then verifies the contents of the autocomplete dropdo ...

How to retrieve a variable from an object within an array using AngularJS code

I recently started learning TypeScript and AngularJS, and I've created a new class like the following: [*.ts] export class Test{ test: string; constructor(foo: string){ this.test = foo; } } Now, I want to create multiple in ...

Issues with locating the fonts: React-slick paired with nextjs

Incorporating react-slick into a NextJs project has been quite seamless, however, I'm encountering issues with importing the necessary fonts from the CSS files. To address this snag, I've attempted the following steps: npm install slick-carouse ...

What is the best way to elegantly finish a live CSS animation when hovering?

Currently, I am working on a planet orbit code where I want to enhance the animation speed upon hover. The goal is for the animation to complete one final cycle at the new speed and then come to a stop. I have been successful in increasing the speed on hov ...

AngularJS fails to prioritize the following element

Here is my HTML code: <div ng-app="app"> <form> <div class="form-group"> <label >Username</label> <input focus type="text" class="form-control" id="loginUserName" ng-model="userForm.crn" required/> ...

How to bind clickable labels to a model using a radio button in .NET Core?

Trying to create a radio button list in asp.net core that is bound to a model while also having clickable unique labels associated with each option. Currently, here is the code snippet: <fieldset> <div> <span> ...

What could be hindering the activation of my button click event?

Below is the js file I am currently working with: var ButtonMaximizer = { setup: function () { $(this).click(function(){ console.log("The maximize button was clicked!"); }); } }; $(docum ...

List generated by BeautifulSoup contains duplicate entries - require a distinct linked list

I am currently attempting to compile a list of unique year links from a specific website (referenced below). Whenever I use the append function, it generates a lengthy list with repeated entries. My goal is to obtain a list that only consists of distinct ...

Adjust the background hue of the Row in the Table

Is there a way to update the background color of a Table Row? I attempted using "BackgroundColor" but didn't see any changes Any suggestions on how to fix this issue? <TableRow style={{ backgroundColor: "#FF0000" }}> <TableCell& ...

Maximizing the width of an absolute div element inside a container

Looking at this demo, you'll notice that the header remains fixed. However, my issue lies in getting the absolute <div> inside the <th> to occupy 100% of the width of the <th> When I set width: 100% for the <div>, it expands t ...

Tips for aligning the navigation bar, main content, and footer in the center

Exploring the realm of web coding for the first time, I find myself in need of some guidance. My current project involves creating a webpage for the local sports team to replace their outdated one on Wordpress. Finding the platform not very user-friendly, ...

How can I retrieve the current background color and revert it back after a .hover event?

I am trying to use the .hover function to change the background color of a menu. Each menu item has a different background color, so I want it to return to its original color when the user hovers off. In other words, I want the script to read the current b ...

What is the best way to include a parameter in the current URL in Django using Paginator?

After setting up a page to display database data, I added a paginator and a search bar to my website. When a user searches for something, the URL changes to include the search query like this: .../search/?q=xyz However, when paginating the search results ...

Using the bootstrap container-fluid to create additional space on the right side

I've been trying to remove the right side padding in my container-fluid without success. There seems to be extra space where the red lines are marked. I have attempted various methods to fix this issue but I can't seem to identify where this ex ...

Disabling the Entire Page Using Jquery

I've got this cool ajax function function do_ajax_request(t){ var form = $('#edit_'+t); var loadingDiv = $('#loading_'+t); $.ajax({ url: form.attr("action"), type: "POST", data: form.serialize(), cach ...

Dealing with a large amount of HTML content following an Ajax request: best practices

I'm currently using a method that works fine, but I can't stop thinking about whether there might be a better way to achieve the same result. The task at hand is to display a user profile in a modal box. When a user clicks on a button or link, a ...

Tips for aligning a div containing an image in the center of another div

Trying to perfectly center an image inside a div both vertically and horizontally using the display inline-block property. HTML <div class="center-wrapper"> <div class="image-holder"> <img src="picture.jpeg" alt="Centered Image"> ...

Tips for properly positioning the ko validation message in case it is lengthy

I have implemented ko validation messages in order to validate input fields. Can anyone provide guidance on how to align the validation message correctly within the specified location? <input id="personName" class="form-control placeholder has-error" t ...

Prevent tooltips from displaying outside of an HTML table by using the overflow hidden property for horizontal scrolling

TL;DR: Struggling to position and display tooltips in a table due to the constraints of overflow: hidden. An example has been created to demonstrate the issue with tooltips not displaying correctly within a table. The problem arises because the table nece ...