简体   繁体   English

如何使菜单的最小高度与标题相同?

[英]How can I make the min-height of my menu the same as my header?

So I have this issue on smaller screens. 所以我在较小的屏幕上遇到这个问题。 I want my menu to be 100% height and 100% width - 25px margin on all side. 我希望菜单高度为100%,宽度为100%-所有边距均为25px。 The probleem is when someone has a small screen I can see the header content(text) under my menu because of my 25px botton margin. 问题是当某人的屏幕较小时,由于我的25px装箱边距,我可以在菜单下看到标题内容(文本)。 Is there a way I can fix this? 有办法解决这个问题吗?

https://jsfiddle.net/vh2zugku/1/ https://jsfiddle.net/vh2zugku/1/

position: absolute;
top: 25px;
right: 25px;
left: 25px;
z-index: 1;
height: calc(100% - 50px);
margin: auto;
color: white;
background: $Black;
opacity: 0;
visibility: hidden;
padding: 0;
overflow: hidden;

This may look strange but pls play with the height and see what I mean. 这可能看起来很奇怪,但是请随身携带,看看我的意思。

If the background is a solid color, you could just use a border instead of a gap. 如果背景是纯色,则可以使用边框而不是间隙。 Just make sure the border is the same color as the document background. 只需确保边框与文档背景的颜色相同即可。

This would look like something along the lines of: 这看起来类似于以下内容:

.overlay {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  /* height is removed but you could set it to 100% */
  border: 25px solid #F3F5F6;
  ...
}

Also, in lieu of another comment on the question itself, here is a quick fiddle that sets a body class when the menu is opened and removes it when it closes. 另外,代替对问题本身的另一条评论, 这里有一个快速提琴 ,它在菜单打开时设置主体类,在菜单关闭时将其删除。 (This is in response to your comment above.) This class sets the body to position: fixed . (这是对您上面的评论的回应。)此类将主体设置为position: fixed It prevents scrolling. 它防止滚动。 You could also use overflow:hidden on the body to achieve a similar effect. 您也可以在身体上使用overflow:hidden以达到类似的效果。

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

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