How to create a 3 column layout structure in react.js
const Columns = () =>
<div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gridGap: 20 }}>
<div>Column 1</div>
<div>Column 2</div>
<div>Column 3</div>
</div>
ReactDOM.render(<Columns />, document.getElementById("root"))
Related videos on Youtube
soccerway
I am an automation tester by profession. During the spare time I love to read technical blogs, watching technical videos enjoy scripting, coding and play soccer. Now I am working on Reactjs, React-hooks, Express, Axios, Sequelize.js to build a web app for fun. I prefer Cypress or Playwright over Selenium Web driver to automate stuff.
Updated on June 04, 2022Comments
-
soccerway almost 2 years
I have started learning about
React js
. Now I am building a blog page ideally a 3 column layout usingReact.js
. Is there an efficient way of creating a simple 3 column layout, where I couldstyle
the columns. Created an App.js file and created files using Blog.js, BlogItem.js under components folder, but how to pass 3 column structure layout in React.js ? Please advise// App.js :
import React, {Component}from 'react'; import Blog from './components/Blog' import './App.css'; class App extends Component { state={ blogs:[ { id: 1, title:'Javascript blog', completed: false }, { id: 2, title:'Cypress blog', completed: false }, { id: 3, title:'Testing blog', completed: false }, { id: 4, title:'Java multi threading blog', completed: false }, { id: 5, title:'Puppeteer blog', completed: false }, { id: 6, title:'React Examples', completed: false } ] } render(){ console.log(this.state.blogs) return ( <div className="App"> <Blog blogs={this.state.blogs}/> </div> ); } } export default App;
//Blog.js
import React, {Component}from 'react'; import BlogItem from './BlogItem'; import PropTypes from 'prop-types'; class Blog extends Component { render(){ return this.props.blogs.map((blog)=>( <BlogItem key={blog.id} blog={blog}/> )); } } // PropTypes Blog.propTypes={ blog: PropTypes.array.isRequired } export default Blog;
//BlogItem.js:
import React, { Component } from 'react' import PropTypes from 'prop-types'; export class BlogItem extends Component { render() { return ( <div style={blogStyle}> <p>{this.props.blog.title}</p> </div> ) } } // PropTypes BlogItem.prototypes ={ blog: PropTypes.object.isRequired } const blogStyle ={ backgroundColor: '#c7c6c1' } export default BlogItem
// Output as of now:
-
Yuvi over 4 yearsYou could create a Table Component and its props would be rows and columns (in your case would look like id, title & completed). The rows would be your data which you could map using columns.
-
soccerway over 4 yearsI am looking for a normal '3 column ' div layout, sorry not a table one.
-
coreyward over 4 yearsReactJS has no layout or styling capabilities outside of HTML and CSS, so this isn't really a React or JavaScript question.
-
-
soccerway over 4 yearsWhere do I need to add the
const Columns = {...
, should I add that inApp.js file
? -
coreyward over 4 years@soccerway Totally up to you. If you're not yet familiar with React basics they have some pretty solid tutorials here.
-
soccerway over 4 yearsI figured out on how to use the style, awesome help coreward