Can one use Flexbox inside another Flexbox?

I am attempting to create a layout that looks like this:

+---------+---------------------+
|legend   |                     |
+---------+                     |
|csv_input|        map          |
|         |                     |
|         |                     |
|         |                     |
+---------+---------------------+

+---------+-------+
|legend   |       |
+---------+  map  |
|csv_input|       |
|         |       |
+---------+-------+

https://jsfiddle.net/zwjm16p3/1/

Using the following HTML and CSS:

*,
*:before,
*:after {
  box-sizing: border-box;
}
html,
body,
div#wrapper,
div#map {
  height: 100%;
}
body {
  padding: 0;
  margin: 0;
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}
#wrapper {
  display: flex;
  flex: 1;
  background: #fef;
}
#map {
  flex: 1;
  background: #ffe;
}
#sidebar {
  order: -1;
  flex: 0 0 20em;
  height: 100%;
  background: #eff;
}
#sidebar_wrapper {
  height: 100%;
  width: 100%;
  background: #eef;
  display: flex;
  min-height: 100vh;
  flex-direction: row;
}
#legend {
  width: 100%;
  background: #efe;
  flex: 2em 0 0 0;
}
#csv_input {
  width: 100%;
  background: #eef;
  flex: 1;
}
<div id="wrapper">
  <div id="map"></div>
  <div id="sidebar">
    <div id="sidebar_wrapper">
      <div id="legend">
        Paste CSV data below.
      </div>
      <textarea id="csv_input"></textarea>
    </div>
  </div>
</div>

This is what I am currently seeing:

+----+----+---------------------+
|lege|csv_|                     |
|    |    |                     |
|    |    |        map          |
|    |    |                     |
|    |    |                     |
|    |    |                     |
+----+----+---------------------+

I have two inquiries:

  1. Why is flex-direction: row; not taking effect?
  2. Do I need the #sidebar_wrapper div, or can a div both be the child in one flexbox and the container of another?

Answer №1

To achieve the desired layout, you need to encompass all the divs within a single flex box with flex-direction: row. Additionally, the two inner divs should be enclosed in separate flex boxes with flex-direction: column.

#wrapper{
 display:flex;
 flex-direction:row;
}
#sidebar{
 display:flex;
 flex-direction: column;
}

You can view a functioning demonstration of this solution here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Could you kindly repair the table for me?

I have a table that I am working on. All values and buttons in the table need to be centered horizontally and vertically. However, there is an issue where if I enter a button link as a value of any row, the button and other text values become broken and ...

How can jQuery determine the amount of line breaks within a div element?

My div wrap size is a percentage of the screen width, containing multiple .item divs that break into new lines as the window size decreases. I attempted to calculate the total number of boxes that could fit based on their widths compared to the container ...

Break down the organization of CSS

While exploring a website, I came across this CSS code that sets the font family to "Open Sans," Helvetica, Arial, and sans-serif. However, I am having trouble understanding this structure. Any assistance would be greatly appreciated. Thank you in advanc ...

Incorporating a variety of background images and colors into a navigation bar

Hey there, I could really use some assistance with a design challenge I'm facing. My goal is to have a navigation bar with two different background colors - most of the list items should have a red background, while one specific item needs to have a b ...

Implementing the linking of a URL to an HTML hidden button that is dynamically displayed through a Javascript program

I'm currently developing a basic webpage that has a feature allowing users to download the final result as an image file in the last step. To achieve this, I've added a hidden HTML button for downloading the result image and used CSS to set its ...

Loading event in HTML5 video element is in progress

I'm interested in creating a loading animation for an html5 video, similar to the display on Youtube videos (reference: https://www.youtube.com/watch?v=5vcCBHVyG50) I attempted using the canplay event but I believe I may have misunderstood its true p ...

The height and rows of a textarea element do not adjust properly to the content in FireFox

Looking for a way to create a textarea with dynamic height that adjusts as the user adds new content? The resize property is set to none and overflow is hidden. It seems to be working correctly in Chrome, but Firefox is presenting some mysterious issues wi ...

Retrieve data from an HTML table with the power of jQuery

I have a table with the following structure. <form id="myform"> <table> <tr><th>TEST</th> <th>VALUES</th> <th>UNIT</th> <tr><td>Abc</td><td><input type="text" & ...

How can I prevent my carousel div from aligning with the NavBar on the same line?

I recently created a simple HTML landing page template, which includes a navigation bar in the header section and a carousel displaying various icons in the body. However, I am facing an issue where both elements are appearing together instead of on separa ...

Hover animation using CSS is a great way to add interactivity

I'm trying to create an animation in a moving box that flips upside down when the mouse is raised. I've attempted to use keyframes and hover to achieve this effect, but it's not working as expected. Any suggestions on how to make it work? ...

Creating a repeated design using linear gradients in CSS

As I venture into the realm of Photoshop patterns for the first time, I am working on a webpage where I plan to incorporate these patterns to enhance the background. The pattern I have discovered measures 120x120 px. If I were to stop here, I would simpl ...

Disrupting Alignment Due to Input Tag

Hey there, I'm having an issue with my header design. I have a horizontal list of links in my header, and next to them, I wanted to add a search bar. Unfortunately, when I added the search bar next to the links, they all ended up appearing behind my b ...

How to effectively implement light and dark themes using SCSS colors?

Currently, I am utilizing Vue.js and SCSS along with PrimeVue and Element plus, where I am importing their variables. My objective is to dynamically change the theme color. In my dark-variables.scss file, I have defined various color variables for differe ...

iframe failing to load link after initial attempt

As a beginner in using iframes, I have come across an issue that is puzzling me. I have a navigation bar and an iframe on my webpage. When I click on the "Search" link, it loads into the iframe without any problems and I can work within it. However, if I c ...

Updating divs automatically using Ajax without refreshing the page is not functioning as intended

I'm having trouble understanding why this isn't functioning properly. My goal is to have the data from load.php displayed in the div sample. However, if the code is updated (for example, when pulling information from a database), I want only the ...

Removing outlines on <p> <a> or <div> elements with Ionic and Angular seems to be a challenging task

Hey there, I’m currently working on my application which includes a login page. I've implemented a “Forgotten password ?” link, but no matter what I try, like using .class and :focus {outline: none}, I still see a yellow square around the item. ...

Clickable div containing a hyperlink

I need assistance with a clickable div that contains a link. Here is the setup: HTML: <div onClick="goToCat(2);" class="author-topics-block "> <a href="http://mywebsite/page/?cat=2">The woman in steel</a> </div> CSS: .author ...

What causes jQuery's append function to trigger a redraw of my Div?

I have a unique function that incrementally increases the date by one day every second. Once the date matches specific dates, I aim to update my #newsDiv with extra text content. The #newsDiv will display all historical "news" and will be set to scroll to ...

Ensure selected language is maintained when refreshing or changing view by utilizing switch i18n functionality

Hello there, I am facing a challenge with "JavaScript Localization" on my website. The issue is that I cannot figure out how to prevent the DOM from prioritizing the local language of the browser and instead use the language set in the switch as a referenc ...

Meta tags are causing issues with HTML5 validation on the website

Striving to enhance the HTML validity of my website, I encountered several errors in the meta tags that are marked as invalid. Unfortunately, I am unsure how to modify them to rectify these errors. <meta http-equiv="X-UA-Compatible" content="IE=edge,ch ...