Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React: Flexbox using inline styles with react router

I am using react router to navigate to different routes in my application on sidebar. I am using inline styling for react for all the designs. Moreover, I am using flexbox to achieve design. I am new to flex and haven't completely grasped the concept for the styling. This is basically what I want to make: enter image description here

app.jsx

render() {
    const styles = {
        container: {
            display: 'flex',
            height: '100%'
        },
        sidebar: {
            container: {
                backgroundColor: 'blue'
            }
        },
        header : {
            width: '100%'
        }
    };
    return (
        <div style={styles.container}>
            <Sidebar style={styles.sidebar} links={sidebarLinks} />
            <Header />
            {this.props.children}
            <Footer />
        </div>
    );
}

Thank you in advance!

like image 986
Umair Avatar asked Sep 17 '26 04:09

Umair


1 Answers

I made an example regarding your question

var Hello = React.createClass({
  render: function() {
    const styles = {
           main: {
             margin: 0,
             padding: 0,
             display: 'flex',
             height: '600',
             flexDirection: 'column'
          },
          article: {
             margin: '4px',
             padding: '5px',
             borderRadius: '7pt',
             background: 'red',
             flex: 6,
             order: 2,
             alignItems: 'stretch'
          },
          header: {
             margin: '4px',
             padding: '5px',
             borderRadius: '7pt',
             background: 'green',
             flex: 1,
             order: 1
          },
          footer: {
             margin: '4px',
             padding: '5px',
             borderRadius: '7pt',
             background: 'blue',
             flex: 1,
             order: 3
          }
        }
    return (
        <div style={styles.main}>
          <article style={styles.article}>
            <p>this is your content</p>
          </article>
          <header style={styles.header}>header</header>
          <footer style={styles.footer}>footer</footer>
        </div>
    )
  }
});

ReactDOM.render(
  <Hello />,
  document.getElementById('container')
);

The basic idea is use "flex" in style to control the ratios of components. For instance, the "flex" of my header, article, footer are 1, 6, 1. So the ratios of heights are 1:6:1. Besides, you can control the orders of components by 'order'

like image 88
LawBee Avatar answered Sep 20 '26 15:09

LawBee