简单的 HTML / CSS 问题 - 高度和高度屏幕分辨率

发布于 2024-11-29 18:46:40 字数 167 浏览 7 评论 0原文

我需要使 div 具有一定的高度,它里面有一个重复的图像,我希望它占据整个屏幕,无论用户的屏幕分辨率是多少。自动高度取决于内容,所以我需要使用 javascript 来实现我的目标吗?或者我可以使用带有“clear:both;”的东西吗?它的属性以便始终将 div 拉伸到底部?我真的很想避免使用 JavaScript。

I need to make a div have a certain height, it has a repeating image in it and I want it to take up the entire screen no matter what the users screen resolution is. Height auto depends on the content so do I need to use javascript in order to achieve my goal? Or can I use something with a "clear:both;" property on it in order to always stretch the div to the bottom? I would really like to avoid javascript.

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

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

发布评论

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

评论(2

无所的.畏惧 2024-12-06 18:46:41

只要父容器(如 bodyhtml)具有 100% 高度,那么 div 也应该。例如

html, body{
    height:100%;
}
div{
    height:100%;
    width:100%;
    border:1px solid red;
}

http://jsfiddle.net/jasongennaro/Jm8Mt/

当然,您的div 将有一个 class...示例仅供展示

As long as the parent container (like body or html) has 100% height, then the div should also. So

html, body{
    height:100%;
}
div{
    height:100%;
    width:100%;
    border:1px solid red;
}

Example: http://jsfiddle.net/jasongennaro/Jm8Mt/

Of course, your div would have a class... example was just for show

江心雾 2024-12-06 18:46:41

给 div 100% 的高度和宽度将使其占据整个窗口。

#fullscreen {
height:100%;
width:100%;
}

Giving the div 100% height and width will make it take up the entire of the window.

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