css - react : Flexbox using inline styles with react router

标签 css reactjs flexbox react-router inline-styles

我正在使用 React 路由器在侧边栏上导航到我的应用程序中的不同路由。我正在使用内联样式对所有设计使用react。而且,我正在使用flexbox来实现设计。我是 flex 的新手,还没有完全掌握样式的概念。 这基本上就是我想要做的: 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>
    );
}

提前致谢!

最佳答案

我做了一个 example关于你的问题

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')
);

基本思想是在风格上使用“flex”来控制组件的比例。 例如,我的页眉、文章、页脚的“flex”是1、6、1。所以高度的比例是1:6:1。 此外,您可以通过'order'控制组件的顺序

关于css - react : Flexbox using inline styles with react router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38541115/

相关文章:

javascript - 我怎样才能得到这个机制?

html - 是否可以为超过两个具有不同高度的元素的 HTML 元素实现正确的 Material 设计阴影?

javascript - 如何在 React 中使用外部 jquery 插件

html - 具有动态元素高度的 Flexbox 列

javascript - 将 Canvas 大小调整为其父元素 ion-grid

html - Flexbox 重新排列 2 个嵌套元素之间的顺序

javascript - 自定义字体在显示之前不会加载(显示时不会加载 : none)

css - 删除 styleClass 时 applyCss 不起作用

javascript - 如何从 React JS (ES6) 中的对象内的数组中删除元素

javascript - 错误: Unable to locate env file at default locations (./.env,./.env.js,./.env.json)