0

Check this fiddle. I'd like to know how to remove the space between lines. I've already tried removing <br />, but nothing changes. Also I don't want to put negative values for margin-bottom. I don't know whether it's a react or css matter.

HTML

<div id="app"></div>

CSS

div.square {
  display: inline-block;
  width: 20px;
  height: 20px;
}

React

class Square extends React.Component {
    constructor(props) {
        super(props);
        this.style = {
            backgroundColor: 'yellow',
            borderStyle: 'solid',
            borderWidth: 1
        }
    }
    render () {
        return (<div class = "square" style = {this.style}></div>);
    }
}

class App extends React.Component {
  constructor(props) {
    super(props);
  }

  render() {
    var ret = [];
    for (var i = 0; i < this.props.m; i++) {
        for (var j = 0; j < this.props.n; j++) {
            ret.push(<Square></Square>);
        }
        ret.push(<br />);
    }
    return ret;
  }
}

ReactDOM.render(<App m = "10" n = "10" />,document.querySelector("#app"));
CSS Monteiro
  • 71
  • 1
  • 1
  • 8

1 Answers1

0

Keep in mind that class is reserved for creating components in react. So to add css class names to jsx elements you should use className prop instead of class

Change

 render () {
    return (<div class = "square" style = {this.style}></div>);
}

To

 render () {
    return (<div className= "square" style = {this.style}></div>);
}

And change your css to

 div.square {
     display:inline-block; 
     margin:0;
     vertical-align:top;
     width: 20px;
     height: 20px;
  }
Hemadri Dasari
  • 32,666
  • 37
  • 119
  • 162