如何制作全屏div,并防止内容改变大小?
对于我的网络应用程序,我希望主 div 为全屏(宽度和高度 = 100%),并且无论内容如何,我希望它保持该大小。这意味着,如果内容不多,它不应该收缩,如果内容太多,它不应该推这个主div。
我该怎么做?
(我同意对这个 div 进行黑客攻击,只要它能保持内容不受黑客攻击)
for my web application, i would like the main div to be full screen (both width and height = 100%), and regardless of content, i want it to stay at that size. that means, if there are not much content, it shouldn't shrink, and if there are too much content, it shouldn't push this main div.
how can i do this?
(i'm ok with hacks applied to this div, as long as it will keep contents hack-free)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
或者甚至只是:
(html、body 可以设置为 95%-99% 或类似的值,以解决边距等方面的轻微不一致问题。)
Or even just:
(html, body can be set to like.. 95%-99% or some such to account for slight inconsistencies in margins, etc.)
请注意,其中大多数只能在没有 DOCTYPE 的情况下使用。我正在寻找相同的答案,但我有一个 DOCTYPE。然而,有一种方法可以使用 DOCTYPE 来做到这一点,虽然它不适用于我的网站的样式,但它适用于您想要创建的页面类型:
现在,这在前面提到过,但我只是想澄清这通常与 DOCTYPE, height:100% 一起使用;仅在没有 DOCTYPE 的情况下有效
Notice how most of these can only be used WITHOUT a DOCTYPE. I'm looking for the same answer, but I have a DOCTYPE. There is one way to do it with a DOCTYPE however, although it doesn't apply to the style of my site, but it will work on the type of page you want to create:
Now, this was mentioned earlier but I just wanted to clarify that this is normally used with a DOCTYPE, height:100%; only works without a DOCTYPE
我使用这种方法来绘制模态叠加。
我认为这里的区别在于 position:fixed 的使用,它可能适用也可能不适用于您的用例。
我还添加了 z-index:1000;背景:rgba(50,50,50,.7);
然后,模态内容可以存在于该 div 内,并且页面上已有的任何内容在背景中仍然可见,但在滚动时被覆盖层完全覆盖。
I use this approach for drawing a modal overlay.
I believe the distinction here is the use of position:fixed which may or may not be applicable to your use case.
I also add
z-index:1000; background:rgba(50,50,50,.7);
Then, the modal content can live inside that div, and any content that was already on the page remains visible in the background but covered by the overlay fully while scrolling.
使用 HTML
并使用 CSS:
确保 HTML 位于根元素中。
希望这有帮助!
Use the HTML
and use the CSS:
Make sure that the HTML is in the root element.
Hope this helps!
这是我的解决方案,我认为最好使用
vh
(视口高度)和vw
(视口宽度),与高度
有关的单位和当前视口的宽度
Here is my Solution, I think will better to use
vh
(viewport height) andvw
for (viewport width), units regarding to theheight
andwidth
of the current viewport