全视口高度缩放 ​​div 只是 css 没有 js...可能吗?

发布于 2024-08-06 06:18:58 字数 547 浏览 6 评论 0原文

好的,我正在尝试缩放 div,并且高度始终是视口的高度。我将链接到我的示例,因为它需要一些解释。

www.madmediablitz.com/tv/precentdemo.html

上面的链接是我找到的最接近解决方案的链接,我希望这里有人会发现它很容易修复。我想要发生的是电视始终是视口的高度(在某种程度上,最小高度:~400px;最大高度:~700px;)。我在那里使用的代码基于 http://www.alistapart .com/articles/creating-intrinsic-ratios-for-video/

www.madmediablitz.com/tv/precentdemo_alt.html

这是我不想发生的事情。如果您调整窗口大小,您会发现它不按比例缩放。

我已经尝试这两种方法大约两天了,但一直无法让它发挥作用。我确实在祈祷帮助,因为我认为这并不太复杂。

Ok, I'm trying to get a div to scale and the height is always the height of the viewport. I'm going to link to my examples as it needs some explaining.

www.madmediablitz.com/tv/precentdemo.html

The link above is the closest I've come to a solution and I'm hoping that someone here will find it simple to fix. What I want to happen is the tv to always be the height of the viewport (to a degree, min-height:~400px; max-height:~700px;). The code that I used there is based on http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/.

www.madmediablitz.com/tv/precentdemo_alt.html

This one is what I DON'T want to happen. IF you resize your window you will see it doesn't scale proportionally.

I've been trying both of these for about 2 days now and I haven't been able to get it to work. I'm literally praying for help as I think, this isn't too complicated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

潦草背影 2024-08-13 06:18:58

请看这个:
http://stanhub.com/how-to-make-div-element-100-height-of-browser-window-using-css-only/

<div id="welcome">
   your content on screen 1
</div>

<div id="projects">
   your content on screen 2
</div>
div#welcome {
    height: 100vh;
    background: black;
}

div#projects {
    height: 100vh;
    background: yellow;
}

就是这样。

Please see this:
http://stanhub.com/how-to-make-div-element-100-height-of-browser-window-using-css-only/

<div id="welcome">
   your content on screen 1
</div>

<div id="projects">
   your content on screen 2
</div>
div#welcome {
    height: 100vh;
    background: black;
}

div#projects {
    height: 100vh;
    background: yellow;
}

That's it.

渔村楼浪 2024-08-13 06:18:58
html, body {
  height: 100%;
}

阅读这篇文章。

html, body {
  height: 100%;
}

Read this article.

西瓜 2024-08-13 06:18:58

我猜想,您可以以一种非常令人惊讶的方式使用绝对定位:

div#element {
  position: relative;
}

img.vertical {
  position: absolute;
  top: 0; // no need for px or em 
  bottom: 0;
}

兼容的浏览器应该尝试尊重顶部和底部指令,实际上管理整个高度。

You can use absolute positioning in a quite surprising way I surmise:

div#element {
  position: relative;
}

img.vertical {
  position: absolute;
  top: 0; // no need for px or em 
  bottom: 0;
}

A compliant browser should try to respect both the top and bottom directives, actually managing a full height.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文