Mobile sidebar now includes a button that remains in a fixed position as the sidebar is

I recently added a fixed button to the bottom right corner of my div. Now, I wanted to incorporate a sidebar that slides out on hover and contains a menu. However, when the sidebar is activated through a button click on mobile devices, the fixed button goes off-screen and reappears alongside the sidebar. The sidebar is absolutely positioned within the parent div.

Why does the fixed button move along with the absolute sidebar on mobile devices?

This is an excerpt from my CSS:

.float {
  position: fixed;
  width: 60px;
  height: 60px;
  bottom: 40px;
  right: 20px;
  background-color: #F45866;
  color: #FFF;
  border-radius: 50px;
  text-align: center;
  box-shadow: 2px 2px 3px #999;
}

.my-float {
  margin-top: 22px;
}

.sidebar {
  position: absolute;
  padding: 5px;
  right: -130px;
  transition: 0.3s;
  width: 150px;
  text-decoration: none;
  font-size: 20px;
  color: white;
  border-radius: 25px 0 0 25px;
  background-color: #004687;
  height: 46px;
}

.sidebar:hover {
  right: -20px;
}
<div class="floatingbutton">
  <i class="my-float float">+</i>
</div>

<div class="sidebar">
  Test
</div>

Answer №1

When viewing on a mobile device, the sidebar shifts to the right when in a "collapsed" state, causing the HTML body to extend beyond the screen width. This also pushes the button, which is positioned absolutely, off the screen by approximately 130px too far to the right.

To correct this issue, consider setting a fixed width for the body.

Answer №2

After the sidebar collapsed, the fixed button started to shift due to the body becoming wider and smaller. To resolve this issue, we decided to hide the overflow horizontally in the container.

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

concealing components during screen adjustments

There are 3 identical <div>s available: <div class="box">Hello World!</div> <div class="box">Hello World!</div> <div class="box">Hello World!</div> I need these <div>s to ...

CSS exclusive - achieving a horizontal scrolling list with all list items in a single row

I am working with a div that has a fixed width. Inside this div, there is an unordered list (ul) containing a random number of list items (li) with varying widths. My project utilizes the Bootstrap framework. Below is an example of the code structure: & ...

Can you tell me what is creating the space between the elements in this form?

For an example, take a look at this link: I am puzzled by the gap between the form-group and the button, as well as between the different form-groups. When using Bootstrap 4 with flexbox activated, all my elements (inputs and buttons) collapse without any ...

Apply border-radius to the group of columns in CSS

I'm having trouble applying border-radius to the column group in an HTML table. Is there a solution for this issue that allows me to maintain accessibility for the table view? Is there a way to achieve border-radius on the column group while ensuring ...

What is the best way to implement an object literal method for making an HTTP GET request to retrieve JSON data?

I'm facing an issue with the HTTP GET method when trying to retrieve JSON data. Although the HTTP GET method is successfully fetching the JSON data, I'm struggling to connect it with the object literal. For better clarity, here's the specif ...

Elements styled as inline blocks with static dimensions, irregular in size

Is there a way to ensure that all three boxes are displayed at the same level? Currently, box 2 appears below box 1 and 3 due to having less content. I believe there must be some styling element missing to make each div display at an equal level regardless ...

What steps can I take to correct the footer positioning to appear below the sidebar?

I'm currently struggling with the placement of my sidebar on top of my footer, which is not where it belongs. I would like to move it to the bottom. Take a look at this image for a visual representation of what I'm aiming for. footer { paddi ...

Displaying numerous Google charts within a Bootstrap carousel

A bootstrap carousel has been implemented to showcase our company's data. The carousel includes a bootstrap table, images, and two Google charts: a pie chart and a stacked bar chart. The issue arises when the active class is not maintained for the Go ...

Varying Heights on Different Pages

I have encountered a styling issue while using md-card in my application. The problem arises when I also include md-autocomplete in the home page, requiring me to modify the angular-material.css for proper display. However, on the product page where I uti ...

The next/font feature functions perfectly in all areas except for a single specific component

New Experience with Next.js and Tailwind CSS Exploring the next/font Package Delving into the realm of the new next/font package has been quite interesting. Following the tutorial provided by Next.js made the setup process smooth sailing. I've incorp ...

Is your Chakra UI canvas in React displaying blank with zero width and height?

Here is the link to the codesandbox And here is the code snippet: import "./styles.css"; import { Flex, Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react"; import { SketchField, Tools } from "react-sketc ...

Tips for aligning 'textarea' and 'a' (button) tags in a single row

<div class="row"> <a class="btn btn btn-success btn-block"><i class="fa fa-thumbs-up"></i>Ok</a> </div> <div class="row"> <textarea name="textareaAxs" ></textarea> <a class="btn btn btn- ...

Deactivate the child division by the nth parent division

At the end of my question, I have included a dynamically created div structure with the id "forth-three-one". Now, I need to find a way to disable or hide the input inside this specific div. Directly using the id "forth-three-one" is not an option as it w ...

How can I create a box-shaped outline using Three.js?

As someone new to threejs, I have been trying to figure out how to render a transparent box around a symbol in my canvas. The box should only display a border and the width of this border should be customizable. Currently, I am using wireframe to create a ...

Unable to access all necessary files for app.scss within Laravel

While I am on the journey to master Laravel by following tutorials, I encountered an issue. After running npm install and then npm run dev, I noticed that my app.scss folder is empty and the variables.scss file is missing. I have been tirelessly searching ...

Basic JavaScript framework centered around the Document Object Model (DOM) with a module structure similar to jQuery. Currently facing challenges with

In order to create a simple framework with jQuery style, I have written the following code: (function(window) { window.smp=function smpSelector(selector) { return new smpObj(selector); } function smpObj(selector) { this.length = 0; if (!s ...

In a bootstrap column containing an inner element with a wide width that is taking up more space than intended

I am attempting to create two columns of equal size, containing nested elements with large dimensions and adding overflow: scroll;. However, the column width is defaulting to 100%. Interestingly, when I apply a small width to the column (), the issue is re ...

Customizing a Google chart legend to show on hover event

Utilizing the Google Chart API, I have created a line chart to display my data. To customize the legend, I initially set the chart's original legend to none and then designed my own legend according to my preferences. While everything is functioning ...

Tips for stopping a flex:1 div from expanding to accommodate its abundant content

I'm facing a situation where I need to create two columns, one fixed at 150px and the other filling up the remaining space with scroll functionality for overflow content. Despite trying to use flexbox for this layout, the second column keeps expanding ...

The function driver.find_element is unable to locate an element using the "class_name" attribute

My attempt at using driver.find_element, with the "class_name" method to locate and click on a button for expanding rooms on this website resulted in an error message: raise exception_class(message, screen, stacktrace) selenium.common.exceptions.N ...