问题描述
我想为一个应用程序流畅的布局,我有一些麻烦使用css的高度百分比。它正在使用窗口的水平尺寸来指定高度%,当我想它从窗口的垂直尺寸获得这个百分比。这是可能还是我不幸运?
I am trying to make a fluid layout for an app and am having some trouble with using css for height percentages. It is using the horizontal size of the window to specify the height % when I want it to be getting this percentage from the vertical size of the window. Is this possible or am I out of luck?
width: x%;
height: y%;
x和y是我想要元素的百分比。
x and y being the percentage that I want the element to be. Both are being determined by the horizontal size of the window, and I want each to use it's respective axis.
推荐答案
如果你使用的是窗口的水平尺寸, JavaScript来更新父节点的绝对高度,height%开始意味着什么。从玩耍,P或DIV作为身体的第一代孩子忽略任何CSS高度%;包装在绝对高度的东西。如果你之前不知道高度,请使用onload JS函数来设置它。
If you use JavaScript to update the absolute height of the parent node, height % begins to mean something. From playing around, a P or DIV as first generation child of the body ignores any CSS height%; Wrap it in something with an absolute height. If you don't know the height before hand, use an onload JS function to set it.
这篇关于使用垂直百分比css - height:x%;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!