html - Svg 内部未与中心对齐

标签 html css reactjs svg

我正在使用react并在渲染时,我在div中返回一个SVG。我的代码如下所示:

render() {
    return(
        <div class="myClass">
          <svg> ... </svg>
        </div>
    );
}

我的 CSS 类看起来像:

.myClass{
  margin-left: auto;
  margin-right:auto;
}

它在 Chrome 和 Firefox 中工作得很好,它的 IE 中 svg 显示在左侧,而不是居中对齐。 IE 是否需要添加更多 CSS 属性?

最佳答案

解决了。奇怪的是,IE 将 SVG 视为文本。 我在我的 CSS 类中添加了一个中心对齐并且它起作用了。

我的解决方案是:

.myClass{
  margin-left: auto;
  margin-right:auto;
  text-align: center;
}

关于html - Svg 内部未与中心对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41050046/

相关文章:

javascript - React Native 中的动态颜色

javascript - 使用 id 'user' +i 的复选框切换 id 'checkbox' +i 的属性

javascript - 将静态 HTML 页面转换为动态生成的 jQuery

javascript - sass:vh 和 px 之间的计算

asp.net - 如何获取 GridView 中单元格的固定大小(尤其是宽度)?

javascript - react : Access ref passed between components via render props

html - R在多个html标签之间提取结构化数据

html - 如何在 Rails 中设置 collection_select 的 HTML 选项?

html - 当输入字段的数量未知时,将 2 个输入字段放在同一行

javascript - React 中的 <body> 和 <html> 样式?