Whenever I place my cursor over a button, the adjacent button shifts to the right

This website was created as a project

<!DOCTYPE html>

<html>
<head>
<title>
    Anivies
</title>
<link rel="shortcut icon" href="non.jpg" type="image/png">
<style>

There seems to be an issue with the CSS. Every time I hover over the "anime" button, it causes the "movie" button to move to the right. This was not covered in our lessons, but I've tried to figure it out without success.

body{
    margin: 0px;
    background-color: #cecece;
}

.header{
    width: 100%;
    height: 68px;
    background-color: #000000;  
    position: fixed;
    top: 0px;
    padding-top: 10px;
    padding-left: 7px;
}
.headcon{
    width: 100%;
    height: 73px;
    background-color:#cecece ;
    position: fixed;
    height: 100%;
    width: 100%;
}
.body{
    margin:0px;
    height: 100%;
    width: 100%;
    position:fixed;
    top:50px;
    float: left;
    clear: both;
    overflow: hidden;
}
.footer{
    width: 100%;
    height: 50px;
    background-color: #000000;
    position: fixed;
    bottom: 0px;
}
.button{
    border: 0px;
    height: 55px;
    width: 100px;
    background-color: white;
    position: relative;

}
.button:hover{
    opacity: 0.5;
    background-color:#f43f3f;
    box-shadow: 4px 5px 7px;
    transition:all 0.3s ease 0s;
    cursor:pointer;
}
p{
    font-family: batmanforeveralternate;
    font-size: 17px;
}
.butcon{
    float: left;
    overflow: hidden;
    margin-left: 10px;
    position: relative;
}
#Animelist, #Movielist{
    display: none;
    background-color: gray;
    height: 100px;
    width: 200px;
 }
 }

Jquery

 </style>
 <script src= "JQuery/jquery-1.12.0.js"></script>
 <script>
    //FirstButton   
    $(document).ready(function(){
    $("#but1").hover(function(){
    $("#Animelist").stop().slideToggle(300);
    });
    });

    //SecondButton
    $(document).ready(function(){
    $("#but2").hover(function(){
    $("#Movielist").stop().slideToggle(300);
    });
    });
</script>
</head>
<body>
<div class="headcon">
<div class="header">
<div class="butcon">
        <button class="button">
            <div id="but1"><p>Anime</p></div>
        </button>   
        <div id="Animelist">
            <a href="#">One</a>
        </div>
</div>
<div class="butcon">
        <button class="button">
            <div id="but2"><p>Movies</p></div>
        </button>
        <div id="Movielist">
            <a href="#">One</a>
        </div>
</div>
    </div>  


<div class="body">
</div>

<div class="footer">
</div>
</div>
</div>
</body>
</html>

Answer №1

Make sure to include position: absolute; in the CSS for #Animelist and #Movielist.

//FirstButton   
$(document).ready(function() {
  $("#but1, #Animelist").hover(function() {
    $("#Animelist").stop().slideToggle(300);
  });

  //SecondButton
  $("#but2, #Movielist").hover(function() {
    $("#Movielist").stop().slideToggle(300);
  });
});
body {
  margin: 0px;
  background-color: #cecece;
}

.header {
  width: 100%;
  height: 68px;
  background-color: #000000;
  position: fixed;
  top: 0px;
  padding-top: 10px;
  padding-left: 7px;
}

.headcon {
  width: 100%;
  height: 73px;
  background-color: #cecece;
  position: fixed;
  height: 100%;
  width: 100%;
}

.body {
  margin: 0px;
  height: 100%;
  width: 100%;
  position: fixed;
  top: 50px;
  float: left;
  clear: both;
  overflow: hidden;
}

.footer {
  width: 100%;
  height: 50px;
  background-color: #000000;
  position: fixed;
  bottom: 0px;
}

.button {
  border: 0px;
  height: 55px;
  width: 100px;
  background-color: white;
  position: relative;
}

.button:hover {
  opacity: 0.5;
  background-color: #f43f3f;
  box-shadow: 4px 5px 7px;
  transition: all 0.3s ease 0s;
  cursor: pointer;
}

p {
  font-family: batmanforeveralternate;
  font-size: 17px;
}

.butcon {
  float: left;
  overflow: hidden;
  margin-left: 10px;
  position: reletive;
}

#Animelist,
#Movielist {
  display: none;
  background-color: gray;
  height: 100px;
  width: 200px;
  position: absolute;
}


}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="headcon">
  <div class="header">
    <div class="butcon">
      <button class="button">
            <div id="but1"><p>Anime</p></div>
        </button>
      <div id="Animelist">
        <a href="#">One</a>
      </div>
    </div>
    <div class="butcon">
      <button class="button">
            <div id="but2"><p>Movies</p></div>
        </button>
      <div id="Movielist">
        <a href="#">One</a>
      </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

Issue with jQuery hide() function in Internet Explorer 9

I need help with creating a hidden div that becomes visible when a user clicks a link. The code I have works in FF / IE7 / IE8 but not in IE9, where the div is always visible without any content. Any advice is appreciated! <script> $(document).r ...

Ribbon with slanted angle displayed on top of an image using

I am working on creating an angled cornered ribbon to overlay on images. In the screenshot below, you can see that I want to display a "Sold" ribbon on items that have been sold. https://i.sstatic.net/EgZax.png I have shared a link to the codepen where I ...

Widen Textbox Sideways

I recently came across a JQuery plugin that caught my eye: https://github.com/rotundasoftware/jquery.autogrow-textarea After following the provided guide, I found myself stuck without any results. I attempted to implement it within my document.ready() $( ...

What is preventing relative paths from functioning with xsl:include?

I am working with an XSL file that converts to PDF. The top of the page contains a lengthy CSS style declaration: <xsl:attribute-set name="Header"> <xsl:attribute name="font-size"> <xsl:value-of select="$font-size"/> < ...

Having trouble retrieving text from input element using selenium

In my Java/Spring application, I have created an HTML file with radio buttons populated from a database. Now, I am working on writing a Selenium test case to click the radio button. The values for these radio buttons are stored in an Excel sheet that I am ...

Examining a specific element node to see if it contains a certain string

When using PHP Unit with Selenium Server, my goal is to verify if a specific element in an xpath contains a certain string value, like this: <table> <thead></thead> <tbody> <tr> <th>1</th> < ...

Understanding the technique of extracting text from descendant nodes using Xpath

I am facing a scenario similar to this: <div id="m0"> ... <tr> <td></td> <td></td> <td>Radio</td> </tr> </div> <div id="m1"> ... <tr> <td></td> <td>< ...

What is the best way to extract text/html that appears between two consecutive <input> tags?

Is there a straightforward method to extract the text or HTML content located between input tags, even though these tags do not require closing tags? For instance, in the example below, I am looking to retrieve <b>Bob and Tim</b><br>Tim & ...

Spotting the Visible Element; Detecting the Element in

Currently, my webpage has a fixed header and I am facing the challenge of dynamically changing the styling of the li elements within the navigation based on the user's scrolling position. To achieve this, I believe the most effective approach would b ...

"Unlocking the power of Bootstrap modals in Django

Using Django, I have a loop of div elements. When I click on a div, I want a modal to be displayed. Here is my HTML code: {% for object in theobjects %} <div class="row" style="margin-top:0.5%;"> <div name="traitement" <!-- onclic ...

How do I access a specific child from an object/element retrieved by using the elementFromPoint() method in Javascript?

Is there a method to extract the child element from an element or object retrieved by the function elementFromPoint(x, y); Consider the following scenario: var elem = document.elementFromPoint(x, y); Let's assume that the element returned and saved ...

Troubleshooting z-index conflict when using :before pseudo element to emphasize list entries

I am experiencing an issue with highlighting items in a list generated by JSTree using the :before pseudo element. The z-indexes seem to be causing some trouble, as adjusting them results in the highlighting appearing either behind all links or in front of ...

Connect CSS Transition to a click action

Below is the code snippet. When you click on the div, it creates a folding effect to the left. You can view it here. I want to link this effect to the arrows I use for sliding back and forth. For example: The left arrow should move the slide to the l ...

List items that are not in any particular order spilling over onto the next

Having an issue with an unordered list where the list items aren't all on the same line. The 5th element is dropping to the next line even though each item is set to 20% of the container. The math adds up, so not sure what's causing the problem. ...

Tips for preventing the larger background from displaying a scroll on a web page

Specifically tailored for this specific page: I am looking to eliminate the scrollbar at the bottom of the browser, similar to how it appears on this page: Thank you ...

How can screen readers be alerted about freshly loaded content through ajax?

Whenever a user clicks on a button, I want to add more content to the page. The new content will be visually clear, but how can I ensure that screen readers can easily access it? I've come across two best practices that suggest additional steps may b ...

My goal is to extract the usernames of all sellers from the Poshmark webpage using a combination of JavaScript, Cheerio, and Axios

After experimenting with various methods, I've come close to the solution, but it only retrieves one of the div elements I'm looking for... Although I managed to retrieve multiple divs at one point, when I attempted to extract text using the .te ...

Is my page not displaying correctly due to compatibility view?

My client "jordanzad.com" has a website where the main page design appears broken when viewed in compatibility view. Can you help fix this issue? ...

The Chrome extension is unable to add text to the existing window

Lately, I've been attempting to develop an extension that will automatically add a div to the beginning of the current page. I've been following the guide provided on this https://developer.chrome.com/extensions/activeTab page. The code from the ...

`Error with Bootstrap breakpoints in mobile display`

While working on a responsive login layout using Bootstrap 5, I encountered a strange issue. The design looked fine in the web view, but when switching to mobile view, the md and sm breakpoints didn't trigger as expected. However, after pasting the co ...