简体   繁体   English

根据网站高度(不是视口高度)在 CSS 中设置 div 高度

[英]Set div height in CSS based on website height (not viewport height)

I am using Wordpress and I have set up a website using a website builder that has multiple divs that expand the full width of the screen.我正在使用 Wordpress 并且我已经使用网站构建器建立了一个网站,该网站构建器具有多个扩展屏幕的整个宽度的 div。 I want to draw a vertical line across the left side that starts 300px from the top and 100px from the left and extends to the bottom of the web page (not the viewport height).我想在左侧画一条垂直线,从顶部开始 300 像素,从左侧开始 100 像素,并延伸到 web 页面的底部(不是视口高度)。

It should look like this它应该看起来像这样

The solution I found so far is to add a div to the very top and with css draw the line from the starting position, while increasing the size of the div to match the height of the page, like this到目前为止我找到的解决方案是在最顶部添加一个 div,并使用 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 从起始 position 画线,同时增加 div 的大小以匹配页面的高度,就像这样

The challenge I'm facing now is how do I extend the div box to have the height of the page?我现在面临的挑战是如何扩展 div 框以获得页面的高度? It seems it's not possible with CSS alone, but I also haven't been getting far with Javascript either.单独使用 CSS 似乎是不可能的,但我对 Javascript 也没有走得太远。 The ideas I've had are to return the scrollHeight and pass into into a style tag in the HTML div tag, but I haven't been able to get it working either.我的想法是返回 scrollHeight 并传递到 HTML div 标签中的样式标签中,但我也无法让它工作。

Below my CSS/HTML code:在我的 CSS/HTML 代码下方:

CSS/HTML CSS/HTML

 static { float: left; overflow: hidden; position: absolute; flex-direction: column; left: 100px; top: 300px; min-height: 100vh; height: auto; border-left: 1px solid green; }
 <div class="static" id="line"></div>

Thanks谢谢

I hope it will work for you as well.我希望它也对你有用。

 window.onload = function (){ var line = document.getElementById('line'); const page_height = document.body.clientHeight; line.style.height = (page_height - 300)+'px'; }
 .static { overflow: hidden; position: absolute; flex-direction: column; left: 100px; top: 300px; border-left: 3px solid red; }

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

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