【问题标题】:reactjs svg image rendered with zero width and height in IE在 IE 中以零宽度和高度呈现的 reactjs svg 图像
【发布时间】:2017-09-05 19:24:53
【问题描述】:

我创建了一个 ReactJS 组件来在数据表的每一行中显示编辑/删除按钮。

这是我的组件:

import React from 'react';

const iconStyle = {
    border:'none',
    boxShadow:'none',
    backgroundColor:'transparent',
    cursor:'pointer'

};


const RowEditButtons = (props) => {
    const editButton = props.onEdit ?
        <button type="button" className="btn btn-sm btn-secondary" onClick={props.onEdit.bind(null,props.index)} style={iconStyle}>
            <img src="img/icon-pencil.svg" />
        </button>
            : null;
    const deleteButton = props.onDelete ? 
        <button type="button" className="btn btn-sm btn-secondary" onClick={props.onDelete.bind(null,props.index)} style={iconStyle}>
            <img src="img/close-o.svg" />
        </button>
            : null;

    return (
        <div className="btn-group" role="group" aria-label="Edit buttons" >
            {editButton}
            {deleteButton}
        </div>
    );

};

RowEditButtons.propTypes = {
    index: React.PropTypes.number,
    onEdit: React.PropTypes.func,
    onDelete: React.PropTypes.func
};

export default RowEditButtons;

我在 IE 上进行测试(因为这是公司的标准),我注意到有时按钮会显示,有时不会。有时它们会显示在某些行上而不是其他行上。这是不一致的。使用开发工具查看渲染的 DOM 后,我看到按钮和图像都在那里,只有图像具有宽度 =“0”和高度 =“0”。我不确定这里发生了什么,如果是浏览器、reactjs 或引导程序。

有人知道吗?

【问题讨论】:

    标签: html css twitter-bootstrap reactjs svg


    【解决方案1】:

    我刚刚向 img 元素添加了内联样式,将宽度和高度设置为自动。这似乎解决了问题。

    <img style={{width:'auto',height:'auto'}} src="img/icon-pencil.svg" />
    

    【讨论】:

      猜你喜欢
      • 2013-04-06
      • 1970-01-01
      • 2018-05-26
      • 2010-11-26
      • 2016-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多