【发布时间】:2016-11-20 23:21:00
【问题描述】:
根据 css/svg (https://www.w3.org/TR/SVG2/styling.html) 的 W3C 样式指南,我应该能够使用 x/y 属性在 css 中定位某些 svg 元素。
这适用于 chrome + Samsung Galaxy S6(未尝试其他型号/浏览器)。但是,这在 iOS 和我尝试过的一些窗口/htc 设备中不起作用。
这是我正在使用的代码(在 d3.js 的帮助下);
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">
<script data-require="d3@4.0.0" data-semver="4.0.0" src="https://d3js.org/d3.v4.min.js"></script>
<style>
@media handheld,
screen and (max-width: 425px) {
foreignObject {
x: 30;
y: 30;
}
}
</style>
</head>
<body>
<script>
d3.selectAll("body")
.append("svg")
.append("foreignObject")
.attr("width", 30)
.attr("height", 30)
.attr('x', 0)
.attr('y', 0)
.html("hello")
</script>
</body>
</html>
这也是代码的plnk。
我想知道是否有任何解决方法?或者是否有人可以推荐另一种为 x/y 添加响应断点的方法?
谢谢
【问题讨论】:
-
你为什么有
handheld?它被 iOS 忽略(我认为)并被定义(我认为)为 -
哦,还有,
foreignObject没有很好的跨浏览器支持。如果您的目标是良好的报道,我会考虑取消它(和handheld) -
不适用于 Firefox 47/Ubuntu,但适用于 Chrome/Ubuntu
-
@DavidGilbertson 我尝试删除
handheld并将foreignObject更改为rect但不幸的是,iOS 仍然存在同样的问题 -
@TimB 感谢您在 Firefox 上进行测试 - 修改后的帖子,当我只在 chrome 上进行测试时,我不应该认为它适用于所有浏览器
标签: ios css d3.js svg responsive-design