我正在开发一个项目,其中客户希望导航
根据屏幕高度对齐,类似于 margin-left
作为百分比的工作原理屏幕宽度减小。
因此,我给了 margin-top: 20%
和导航
显示该边距,但是当我减小窗口的高度时,它不会根据屏幕进行调整高度,尽管当我减小屏幕宽度时它会起作用。
我的问题不是如何实现这一目标,而是为什么百分比是水平工作而不是垂直工作?
这是一个示例:http://jsfiddle.net/sandeep/5VReY/
I am working on a project in which the client wants the navigation <div>
to align according to the screen height, similar to how margin-left
as a percentage works when screen width is decreased.
So, I gave margin-top: 20%
and navigation <div>
displays that margin, but when I decrease the height of the window it does not adjust according the screen height although it works when I decrease the screen width.
My question is not how can I achieve that, but why does the percentage work horizontally and not vertically?
Here is an example: http://jsfiddle.net/sandeep/5VReY/
发布评论
评论(2)
根据 css 规范,百分比适用于容器块的宽度
请参阅 w3.org 了解更多信息。
The percentage works on the width of the container block, according to the css specifications
See w3.org for more information.
您可以在“auto”中播放具有 margin 属性的 width top/bottom 属性;
如果你有一个像这样的块:
它可能像这样垂直居中:
水平对齐宽度左/右属性可以实现相同的效果。您还可以设置偏移量,以便移动块中心以外的其他点。
在这里,我给您留下了一些示例,说明结合这些属性可以做什么以及如何做。
http://jsfiddle.net/SQDJ6/
You can play width top/bottom properties having margin prop in "auto";
If you have a block like this:
It may be centered verticaly like this:
The same can be achieved for horizontal alignment width left/right properties. You can also have an offset in order to ubicate other point than the center of the block.
Here I leave you some examples of what and how can be done combining these properties.
http://jsfiddle.net/SQDJ6/