css - Y 轴与 translate() 的工作方式相反

标签 css css-transforms

看看下图,实际上 Y+ 轴指向图表的顶部,Y- 轴指向图表的底部。即,正 Y 值表示的点应位于图表顶部,而负 Y 值表示的点应位于图表底部。

enter image description here

但是,当我在我的代码中使用 transform: translate(50px,100px) 时,它会像吹气图像一样显示出来。正如您所看到的,即使平移 Y 值为正,元素也被推向页面底部。

enter image description here

相反,它需要像下图一样(引用“正确格式”框),也就是说,它应该被推向顶部。 (请原谅图片中的拼写错误)

enter image description here

请仔细看图

我的代码:

<!DOCTYPE html>
<html>
<head>
<style> 
div {
    width: 300px;
    height: 100px;
    background-color: yellow;
    border: 1px solid black;
    transform: translate(50px,100px); /* Standard syntax */
}
</style>
</head>
<body>

<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Labore consequatur amet nemo numquam, a perspiciatis maxime necessitatibus laudantium adipisci tempore,
</div>

</body>
</html>

最佳答案

以下是 W3C Spec for Transform Rendering Model 的摘录:

The coordinate space is a coordinate system with two axes: the X axis increases horizontally to the right; the Y axis increases vertically downwards. Three-dimensional transform functions extend this coordinate space into three dimensions, adding a Z axis perpendicular to the plane of the screen, that increases towards the viewer.

enter image description here

如您所见,它使用 Y 轴垂直向下增加的坐标系,因此当您按正值平移时,元素向下移动(而不是向上移动),反之亦然。

关于css - Y 轴与 translate() 的工作方式相反,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41479953/

相关文章:

jquery - 不要覆盖 css 属性,而是使用 jQuery 添加它们

html - 使用变换禁用缩放/旋转动画

html - 如何为倾斜矩形的高度设置动画?

html - 无法让图像在内容长度不同的 div 中排列

javascript - 根据导航菜单中的 url 更改下拉选项

css - 使用 &__* 语法到达父选择器时 SASS/SCSS 悬停

css - 转换后应用过滤器

html - 如何防止在 safari 中缩放 div 中的复选框和下拉菜单

css - 在 parent 中分配 3 个 child

html - 如何通过CSS重定位下拉菜单