Prevent other divs from moving when hovering over in a fluid user interface

When visiting this plunker, I noticed that the id #chat-msgs shifts downward when hovering over All Conversations on a browser with a width less than 767px. I attempted to use position: absolute to fix it, but it didn't work as intended.

@media (max-width: 767px) {
#user-list {
    display: none;
}
#chat-msgs {
  position:absolute;
}

#dropdownMenu2:hover + #user-list, #user-list:hover{  
  display: block;
}
}

Answer №1

It seems like there was some confusion about the usage of position absolute in this context. For optimal results, position absolute should typically be within an element that has a position relative. By doing so, the element will retain its boundaries and not disrupt the flow of other elements unless specified otherwise through CSS.

Specifically, the #user-list should be removed from the flow to prevent it from affecting the layout of surrounding elements.

Consider implementing the following code:

.dropdown{ position: relative; }

#dropdownMenu2:hover + #user-list, #user-list:hover{
   display: block;
   position: absolute;
   width: 100%;
   z-index: 1;
   background: #fff;
 }

Answer №2

Ensure to set the overflow property on your body tag to hidden, especially if you have already addressed overflow in a different part of your code:

body { overflow:hidden; }

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

Tips on concealing sub-menu until cursor hovers over it

I'm currently in the process of creating a navigation bar for a website, but I'm encountering some challenges with the submenu. While I've managed to position the submenu relative to its parent ul, I'm struggling with making it invisibl ...

How to Blend Pseudo-classes in CSS?

If I want the selected text in a link to turn red when hovered over, can I achieve that using the following CSS code? .abc:hover::selection {color: red;} Also, if I have the following link: <a href="123" class="abc">4567890</a ...

Issue with header background images not showing up in Safari browser

On my website, the top header background and the background of the "Kreation Team" Div are not appearing on Safari for iPads and iPhones, but they are visible on iMacs and MacBooks. The background images do not show up on smaller devices. If you compare C ...

Unveil the stunning left-to-right SVG animation

I have two SVG images and I want to create an animation with them. The animation consists of revealing the text "Full Screen" from left to right using the first SVG, and then covering the word "Screen" with the second SVG to reveal the entire second image. ...

When I adjust the size of my browser, the elements on my HTML page shift around

I'm facing an issue where all my elements move when I resize my browser, and I cannot figure out why. How can I ensure that they stay in their respective positions even when the browser is resized? Is there a CSS solution for this? Thank you! body ...

Unable to hyperlink in a div containing the my-auto class in Bootstrap

I am facing an issue with my carousel layout. I have 3 columns, and one column is reserved for Prev & Next carousel controls. These controls are vertically aligned using the my-auto class. However, after adding this class to the column, the links within it ...

Floating top menu

I am currently working on developing a sticky navigation bar that remains in place when scrolling down. However, I encountered an issue where using position: fixed; caused the text to overlap. Unfortunately, I am unable to use jQuery as my professor has ad ...

Using :before and :after in CSS, three dots can be created in a horizontal line

I am currently trying to display three horizontal dots on my webpage. I have created a demonstration on jsfiddle. span { position: relative; background-color: blue; border-radius: 5px; font-size: 0; margin-left: 20px; padding: 5px; ...

Alter the color of the font in every other row

I attempted using the tr:nth-child() selector but it didn't work as expected Here is my JSP and CSS code. The JSP fetches two lists from a Java class, includes a validation if the list is empty, and then displays the values. The data-grid is a table ...

Import Information into Popup Window

When a user clicks on the "view" button, only the details of the corresponding challenge should be displayed: Currently, clicking on the "view" button loads all the challenges. This is because in my view-one-challenge.component.html, I have coded it as fo ...

Ways to generate a distinct identification number for every element within a component instance

I have a ReactJS component that I use in multiple instances. I'm trying to change the CSS elements of each component on click. Initially, I tried referencing the specific component element by ID, but the issue is that all instances currently share t ...

Progress bar display not available

I have recently developed a JavaScript quiz application and included a progress bar feature. While it works flawlessly offline on my laptop, I encountered an issue when uploading the files to Codepen.io - the progress bar fails to display. I would appreci ...

Arranging all text boxes in a horizontal line: A simple guide

Is there a way to align all text boxes in a single row that works properly in both IE and Chrome browsers? IE 11 display: https://i.sstatic.net/wGITo.png Chrome display: https://i.sstatic.net/jXs0r.png Textboxes are not aligned properly as shown below: ...

Tips for adjusting the size of an HTML canvas to fit the screen while preserving the aspect ratio and ensuring the canvas remains fully visible

I'm working on a game project using HTML canvas and javascript. The canvas I am using has dimensions of 1280 x 720 px with a 16:9 aspect ratio. My goal is to have the game displayed at fullscreen, but with black bars shown if the screen ratio is not 1 ...

Margin isn't functioning properly

My section is not centered and adding margin-left doesn't seem to be working. Any suggestions on how I can solve this? Take a look at how it appears. Here's the code: .margins { margin-left: 100px; } <link href="https://cdn.jsdelivr.net ...

"Utilize Bootstrap 4 to create a 5-column row layout featuring lengthy text

I'm familiar with how bootstrap 4 uses col instead of col-xs, but I've encountered an issue. When the text within a column is too long to fit on a small screen, the columns begin to stack below each other. Is there a way to prevent this and set t ...

Create an immediate impact by injecting CSS

I currently have the following code set up: style.js: function applyStyle(str) { var element = document.createElement('style'); element.innerHTML = str; document.body.appendChild(element); } var style = 'body {' style ...

What are the best techniques for positioning text next to images in HTML and CSS?

I have attempted to position the text in close proximity to the images as shown in the picture below (to allow for spacing in the middle). As depicted in the image, the "AVENUE FOR GROWTH" and "NETWORKING OPPORTUNITIES" texts are near Man's hand and w ...

inactive toggle being released

I am facing an issue with my two slider menus, where only the right menu holds the active value when clicked. The left menu slides out only when the toggle button is held down, but I need it to slide out when the toggle is simply clicked and not held down. ...

Images of varying sizes aligned at the bottom of cards, organized in rows with pure CSS styling

I am working on a layout that involves a container with "cards": images positioned above with related text below. Here's an example: <div class = "cards"> <div class = "card"> <div class = "image-wrap"> <img src= "im ...