简体   繁体   English

如何防止汉堡菜单侧边栏溢出大小?

[英]How to prevent hamburger menu sidebar makes overflow the size?

I have a hamburger-like menu on the right side that can bring sidebar from right to the left just like this slide example .我在右侧有一个类似汉堡包的菜单,可以将侧边栏从右移到左,就像这个幻灯片示例一样。

The problem is that the sidebar takes a extra space although it's hidden (before clicking menu) and when it comes out the extra space has been occupied by the sidebar.问题是侧边栏虽然被隐藏(在单击菜单之前)但占用了额外的空间,并且当它出现时,额外的空间已被侧边栏占用。

It looks like body tag is forced to be extended by the sidebar that is not my intention.看起来body标签被侧边栏强制扩展,这不是我的意图。

I want the sidebar to come out the edge of the right side instead of taking extra space when hidden and takes that space when appeared.我希望侧边栏出现在右侧的边缘,而不是在隐藏时占用额外空间并在出现时占用该空间。

Here's my code below:下面是我的代码:

const Sidebar = styled.div<SidebarProps>`
  position: absolute;
  background: rgb(65, 65, 65);
  top: 3.6rem;
  right: 0;
  border: 1px solid red;
  width: 19.2rem;
  height: 100%;
  z-index: 99;
  padding: 2.65rem 1.4rem;
  overflow-y: hidden;
  transform: ${(props) =>
    props.slideOn ? "translateX(0)" : "translateX(100%)"};
  transition: transform 0.3s ease-in-out;
  opacity: ${(props) => (props.slideOn ? 1 : 0)};
`;

Thanks in advance.提前致谢。

This might be a dumb way to do it, but could you set the container's width to something like:这可能是一种愚蠢的方法,但是您可以将容器的宽度设置为:

container {
    max-width: 100vw;
    overflow-x: hidden;
}

Well I think it can work for you.嗯,我认为它可以为你工作。 It is a way to do following.这是一种追随的方式。

.container {
  display: none;
  overflow-x: hidden;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM