代码之家  ›  专栏  ›  技术社区  ›  user3802348

React.js中的样式表

  •  1
  • user3802348  · 技术社区  · 8 年前

    我在React中呈现表格时遇到问题。我的两个主要问题是,我所包含的按钮在其部分中没有正确样式(我希望它们在div中居中,但它们离开了表),并且在有按钮或空表标题的区域中,表边框被切断。有人知道我做错了什么吗?

    当前的外观: enter image description here

    相关代码: 我的表格.js:

    export default class MyTable extends Component {
    constructor(props) {
        super(props);
    }
    
    render() {
        var rows = [];
        this.props.items.forEach(function(item) {
            if (i % 2 === 0) {
                rows.push(<MyTableRow item={item} key={item.name}  />);
        }.bind(this));
    
        return (
            <table className={styles.moduleSection}>
                <thead>
                    <tr>
                        <th {‘Name’} </th>
                        <th className={styles.status}>{'Potential status'}</th>
                    </tr>
                </thead>
                <tbody>{rows}</tbody>
            </table>
        );
    }
    }
    

    我的表格.css:

    .moduleSection {
        background-color: #fff;
        border: 1px solid #ccc;
        border-collapse: collapse;
        border-radius: 6px;
        width: 100%;
    }
    
    .status {
        height: 35px;
        padding: 0 20px;
        text-align: right;
        width: 105px;
    }
    

    我的表格行.js:

    export default class MyTableRow extends Component {
    constructor(props) {
        super(props);
     }
    
    render() {
        const statusMap = {
            1: 'Potential',
            2: 'Unpotential',
        };
    
        return (
            <tr className={styles.tr}>
                <td className={styles.td}>{this.props.conversionTag.name}</td>
                <td className={styles.status}>{item.status}</td>
                <td className={styles.editButton}> <Button
                        text={‘Details'}
                    />
                </td>
            </tr>
        );
    }
    }
    

    我的表格行.css:

    .td {
        font-weight: 500;
        padding: 0 20px;
    }
    
    .status {
        border: 1px solid #e7e7e7;
        color: #ff0000;
        font-size: 14px;
        font-weight: 500;
        padding: 0 20px;
        text-align: right;
    }
    
    .tr {
        border-bottom: 1px solid #e7e7e7;
        font-size: 14px;
    }
    
    .editButtonText {
        padding: 7px 10px;
    }
    
    .editButton {
        background: #fff !important;
        border-color: #c7c7c7;
        border-radius: 4px;
        box-shadow: none;
        color: #333 !important;
        font-size: 14px;
        float: right;
        line-height: 16px;
        padding: 7px 10px;
        width: 48px;
    }
    

    任何帮助都将不胜感激!谢谢

    1 回复  |  直到 8 年前
        1
  •  2
  •   Mario Tacke    8 年前

    有几件事:

    • 你只定义了两个 th 在你的标题中,但有三个 td MyTableRow .

    • 你的 .editButton float: right 设置我想你应该用 text-align: center