【发布时间】:2019-08-25 00:19:20
【问题描述】:
当视口小于 600 像素时,我正在尝试旋转 SVG 制作的图形。我使用了媒体查询,它工作得很好,但是 svg 从它的容器中溢出,无论我做什么,我都无法修复它。
是否可以在没有 javascript 的情况下修复它?
我尝试使用 preserveAspectRatio 属性和 viewbox 属性,但不起作用。
这是代码:https://codepen.io/telumire-the-sasster/pen/vYBxLRg
HTML:
<div class="container">
<svg viewBox="0 0 700 100" preserveAspectRatio="none" class="graphic" style="">
<polyline fill="red" stroke="none"
points="
0,0
0,15
100,14
200,18
300,21
400,23
500,22
600,17
700,17
700,0
0,0
"/>
</svg>
</div>
CSS:
.container {
background-color: green;
}
.graphic {
transform: scaleY(-1);
}
@media (max-width: 599px) {
/* smartphone */
.graphic {
transform: rotate(90deg);
height: 100%;
display: block;
}
}
我希望 svg 不会从绿色容器中溢出(它必须适合它的高度)。
【问题讨论】: