css - 根据元素的高度和宽度转换 X 和 Y 百分比值?

标签 css translate percentage translate3d

将元素 Y 轴平移 50% 会将其向下移动其自高度度的 50%,而不是我预期的父级高度的 50%。我如何告诉翻译元素将其翻译百分比基于父元素?还是我没听懂?

http://jsfiddle.net/4wqEm/2/

最佳答案

translate中使用百分比时,指的是自身的宽度或高度。看看https://davidwalsh.name/css-vertical-center ( demo ):

One interesting thing about CSS transforms is that, when applying them with percentage values, they base that value on the dimensions of the element which they are being implemented on, as opposed to properties like top, right, bottom, left, margin, and padding, which only use the parent's dimensions (or in case of absolute positioning, which uses its closest relative parent).

关于css - 根据元素的高度和宽度转换 X 和 Y 百分比值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11160227/

相关文章:

php - 如何使用 gettext 翻译 MySQL 中的数据?

java - 计算百分比

css - 根据属性重新排序 Div 标签

c++ - 将 Matlab 扰码器函数翻译成 C

java - C 到 Java(二进制数编程)

c# - 计算整数百分比

css - 如何在响应式 View 中按百分比填充剩余宽度?

html - 带有透明边框的响应式箭头进度条

css - 如何使用Perl增加CSS属性值

html - 如何使用固定子 div 固定宽度?