1

In the process of learning basic ReactJS I am trying to create the following layout but I have not been successful in finding solution which leads me to this particular layout which when open on a desktop will look as following (but since it is responsive it will hopefully readjust to screen):

enter image description here

This is the code I am trying but not sure how to take it to a responsive layout I desire.

import React from 'react';

function Header() {
  return (
    <div> I am the header</div>
  )
}

   // each footer is 50% wide
function Footer1() {
  return (
    <div> I am footer 1</div>
  )
}

function Footer2() {
  return (
    <div> I am footer 2</div>
  )
}

// left col has with 84%
function LeftCol() { 
  return (
    <div>
      <form>
        <div>col1 width 84%</div>
        <div>col1 row1</div>
      </form>
    </div>
  )
}

function RightCol() { 
  return (
    <div>
      <form>
        <div>col2 width 16%</div>
        <div>col2 row1</div>
      </form>
    </div>
  )
}

function App() {
  return (
    <div>
      <Header />
      <LeftCol />
      <RightCol />
      <Footer1 />
      <Footer2 />
    </div>
  );
}

export default App;

Edit: I am trying to achieve this using minimal html and CSS but through ReactJS and Material UI as learning exercise.

7
  • Please show your css code as well Commented Jun 21, 2019 at 23:34
  • Or just link a codepen Commented Jun 21, 2019 at 23:34
  • I am going to look into codepen. I am new to react but I have removed the CSS calls from my code as they were not necessary Commented Jun 21, 2019 at 23:37
  • 1
    Welcome to react!! Are you familiar with html, css, or JavaScript? Commented Jun 21, 2019 at 23:38
  • 2
    I would suggest mastering HTML, CSS, and JavaScript, then move onto react Commented Jun 21, 2019 at 23:40

1 Answer 1

1
+50

Something like this might help you.

See if that works for you:

NOTE: This is a very basic integration between React and CSS. If you don't have any experience with CSS I suggest you do the W3Schools CSS course. Once you get it done, I suggest you to look into Styled Components which, in my opinion is a much nicer way to handle CSS in React components. Also a priority to learn React basics in the official documentation and other tutorials.

SNIPPET:

function Header() {
  return(
    <div className="header">I am Header</div>
  );
}

function Main() {
  return(
    <div className="main">
      <LeftCol/>
      <RightCol/>
    </div>
  );
}

function LeftCol() { 
  return (
    <div className="leftCol">
      <div>
        <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>      
      </div>
    </div>
  );
}

function RightCol() { 
  return (
    <div className="rightCol">
      <div>
        <ul>
          <li>Item 1</li>
          <li>Item 2</li>
          <li>Item 3</li>
          <li>Item 4</li>
          <li>Item 5</li>
        </ul>
      </div>
    </div>
  );
}

function Footer() {
  return(
    <div className="footer">I am Footer</div>
  );
}

function App() {
  return(
    <div>
      <Header/>
      <Main/>
      <Footer/>
    </div>
  );
}

ReactDOM.render(<App/>, document.getElementById('root'));
.header {
  width: 100%;                 
  height: 80px;                
  display: flex;               
  align-items: center;         
  justify-content: center;     
  font-weight: bold;           
  background-color: lightblue;
}

.main {
  width: 100%;
  /*height: 200px;*/
  display: flex;
  
}

.leftCol {
  flex: 0 0 84%;
  background-color: lightgreen;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rightCol {
  flex: 0 0 16%;
  background-color: lightgray;
  display: flex;
  align-items: center;
  justify-content: center;
}



.footer {
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: salmon;
  font-weight: bold;
  
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.3/umd/react-dom.production.min.js"></script>
<div id="root"/>

Sign up to request clarification or add additional context in comments.

3 Comments

Is there a way to make the height of the columns responsive as right now it is set to a fixed number ?
You don't have to set them at all. They will adjust based on content height if don't set it. I'll edit the example to show you.
This is a very basic integration between React and CSS. If you don't have any experience with CSS I suggest you do the W3Schools CSS course. Once you get it done, I suggest you to look into Styled Components which, in my opinion is a much nicer way to handle CSS in React components. Also a priority to learn React basics.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.