【发布时间】:2017-12-16 16:01:33
【问题描述】:
我正在尝试在 HTML/CSS 中为我的移动应用程序制作此形状: https://embed.plnkr.co/9k8jbJyzUiSMSoSHlOti/
.boundary {
width: 100.13723%;
padding-bottom: 5.24078%;
position: relative;
overflow: hidden;
background-color: white;
}
.boundary:before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: top left;
transform: rotate(3deg);
background-color: green;
}
.inner {
height: 100%;
width: 100%;
background-color: green;
}
<div class="boundary"></div>
<div class="inner">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis auteirure dolor
in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
在我的浏览器中,当我检查元素并更改缩放(至 75%)时,2 <div> 之间存在间隙。当我在我的设备中部署我的应用程序时,我可以看到同样的差距。
发生了什么事?
这就是我制作形状的方式:
-
我创建了第一个 div 来做斜线。我制作了一个响应式三角形(我从Question 中挑选了一些信息)
1) 在我的 div 中,我插入了第一个伪元素,并为其赋予 100% 的父级宽度和高度。我应用了旋转:我在左上角定义了一个变换原点,并使用
transform: rotate(3deg)将伪元素顺时针旋转了 3 度@2)我必须调整宽度和高度:我使用百分比和
padding-bottom来保持纵横比(more information here)所以:
[rectangle height] : padding-bottom = tan(3deg) * 100% = 100.13723% (100% is the screen width)<br>[hypotenuse of triangle = new rectangle width] : width = tan(3deg) * 100% / sin(3deg) = 5.24078%.
3) 为了隐藏伪元素的不需要的部分(所有溢出 <div> 的红色边框)我在容器上设置了 overflow: hidden。
- 在第一个倾斜
<div>之后,我制作了第二个<div>。这个<div>很简单,没有特殊的转换,并且包含Lorem ipsum。
【问题讨论】:
-
对我来说奇怪的是,使用 Chrome 时,奇怪的行只在“检查”模式下显示,但在其余时间不显示。
标签: html css rotation rectangles