Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I can't get my <main> content to appear to the right of my <nav> content

It’s simplified a bit, but the HTML looks something like this:

.navigationContainer {
  display: flex;
  flex-direction: column;
  width: 243px;
  min-width: 0;
  max-width: 242.91015625px;
  height: 1117px;
  background-color: #374151;
}

.mainContent {
  padding-left: 20%;
  display: flex;
  flex-direction: column;
  row-gap: 40px;
  margin: 16px 50px 50px 0;
  min-width: 0;
  max-width: 1380.60546875px;
}
<nav class="navigationContainer">
  ... navigation
</nav>
<main class="mainContent">
  ... some content
</main>

For some reason, the Main content appears below the Nav content instead of to the right of it. I know that it’s a problem with the CSS, but I can’t figure out what needs to change to get it to appear the way I intend it to. Any help is greatly appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to put your nav and main inside a display:flex, with that element set to flex-direction: row. Right now you’ve declared both elements as being "regular" content blocks, with flex positioning for their child content.

div:has(nav,main) {
  display: flex;
  flex-direction: row;

  nav, main {
    min-height: 100px;
  }

  nav {
    background-color: #c7c1c1;
  }

  main {
    background-color: #a6c7a1;
  }
}
<div>
  <nav class="navigationContainer">
  ... navigation
 </nav>
 <main class="mainContent">
    ... some content
  </main>
</div>

(and that could of course also just be the <body> element rather than a <div>)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading