Choosing between "column" and "row" for a single child's `flex-direction`###ORDeciding on "column

I have a functional layout in place. My goal is to add a vertical scrollbar exclusively for the .gallery-items element, without causing overflow in the .split-panel container.

However, when I attempted to include flex-direction: column to .pane-2, it disrupted the layout unexpectedly.

This leads me to question why this unexpected behavior occurs.

From my understanding, there should be no difference between using flex-direction: row and flex-direction: column when dealing with only one child element.

body {
  margin: 0;
}

.split-panel {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.pane-2 {
  overflow: hidden;
  display: flex;
  /* flex-direction: column; */
}

.gallery {
  display: flex;
  flex-direction: column;
}

.gallery-items {
  display: flex;
  flex-wrap: wrap;
  overflow-y: auto;
}

.item {
  background: teal;
  width: 200px;
  height: 200px;
  margin: 10px;
  display: flex;
}
<div class="split-panel">
  <div class="pane-1">Content</div>
  <hr />
  <div class="pane-2">
    <div class="gallery">
      <div class="toolbar">
        <h1>Title</h1>
      </div>
      <div class="gallery-items">
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
      </div>
    </div>
  </div>
</div>

Answer №1

The gallery element height is being manipulated by the column direction, causing it to fit its content. Setting it explicitly to 100% resolves this issue.

body {
  margin: 0;
}

.split-panel {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.pane-2 {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.gallery {
  display: flex;
  flex-direction: column;
  height: 100%; // <--------------------
}

.gallery-items {
  display: flex;
  flex-wrap: wrap;
  overflow-y: auto;
}

.item {
  background: teal;
  width: 200px;
  height: 200px;
  margin: 10px;
  display: flex;
}
<div class="split-panel">
  <div class="pane-1">Content</div>
  <hr />
  <div class="pane-2">
    <div class="gallery">
      <div class="toolbar">
        <h1>Title</h1>
      </div>
      <div class="gallery-items">
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
        <div class="item">Item</div>
      </div>
    </div>
  </div>
</div>

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

Searchable select option with Bootstrap styling

The bootstrap select option is causing issues for me where it's not functioning properly. $(function() { $('.selectpicker').selectpicker(); }); .sc_table { height: 100vh; overflow: scroll; } <link href="https://cdn.jsdelivr.net/n ...

Tips on modifying the color of three distinct tooltip arrows

I managed to give 3 tooltips different colors using JavaScript and data-toggle like this <span class="tooltipjs" data-toggle="sin-datos" data-placement="right" data-original-title="some text">A</span> $( ...

What is the best method for adding or removing items using ID instead of classes?

Is there a way to change the highlight class to an id, so that clicking outside the products will not trigger the highlight effect? I have added the window.onload section with my desired changes, but I am unsure how to switch the class highlight to an id. ...

The placeholder string is being accepted as the input value for the number

My issue is with a form input of type number. When the form is submitted without entering any number, it treats the placeholder text "rating" as the value. How can I stop this from happening? I need to make sure that the input number field is marked as in ...

Transform or retrieve information from input into unformatted text

I'm working on a JavaScript function that can convert input values to text. However, I am facing an issue as I only want to convert data from one specific row into plain text. Each row in my table has 5 cells along with a button for saving the data. I ...

Best practice is to include the script on a page that is being loaded through ajax

I currently have a webpage named index.php. This page contains a form that takes input numbers and uses ajax to process the form, displaying the result on the same page. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

When printing a PDF, a div that is set to 100vh only takes up

After setting the div to be 100vh, I realized that when printing it only takes up half of the page. Adding media print did not make a difference, and even trying to set the height to 100% instead didn't work for PDFs. html, body { height: 100%; ...

Content that sticks to the footer

I've been utilizing the sticky footer solution found at: This is how the CSS appears: * { margin: 0; } html, body { height: 100%; } .wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -4em; } .footer, .push { height: 4 ...

Adding color to a particular cell within a table using PHP

I'm working on a code that dynamically generates a table with unique IDs for each cell. while ($i <= 30) { echo "<tr id=\"Row{$i}\">"; while ($d <= 90) { $d = $d + 1; echo '<td i ...

Enhancing the functionality of the onclick function within the ng-repeat by incorporating a scope

I am looking to pass a parameter to a function that is called via onclick within an ng-repeat: <!-- Sliding bar (bottom) --> <div ng-show="currentSVG && currentLanguage && currentWidth && bannerHeight" pageslide ps-open=" ...

What methods can be used to restrict video height within a <div> element?

Is there a way to ensure that the bucket-list.mp4 video stays contained within the video-jumbotron div? Currently, the video's height extends beyond the bottom of the page depending on screen size, rather than being cut off and confined within the < ...

The functionality of the footer grid layout in Bootstrap seems to be malfunctioning

I've been struggling to create a footer grid using the Bootstrap layout. Any help would be greatly appreciated. Here's an image of what I'm trying to achieve: I've attempted multiple times but can't seem to make it work <!-- ...

Is It Possible to Run Javascript Code Based on a Specific Screen Size?

Here is the Javascript code I'm currently using to control the mobile menu functionality on my website. It prevents content outside of the menu from scrolling when the mobile menu is open and closes the menu when an item inside it is clicked. document ...

Trigger a PHP script upon choosing an option from a dropdown list in HTML

Currently, this is the markup code I have on my website: <select> <option>1</option> <option>2</option> <option>3</option> </select> I am looking to implement a PHP script that will trigger when a ...

CSS containers not lining up correctly

Currently in the process of developing a web application, I am facing challenges with my CSS panels constantly shifting around unexpectedly. These panels feature an image with a 4:3 aspect ratio along with a description section. While they appear stable ...

Building Custom Navigation for a Multilingual Website in Concrete5

I am trying to build a multilingual website using Concrete5 (v 5.7). My custom theme has the following page layout: Home |-en |--Frontpage |--Contatcs |-<language2> |--<Frontpage> |--<Contacts> The current navigation implementation is ...

The box text shakes when you hover over it

I'm having some trouble with the text in my code interacting with the boxes. Here is a demonstration: http://jsfiddle.net/K6wy3/1/ The issue lies within this section of the code. The box hover effect works fine, but the text seems to flash and jitter ...

Creating sibling classes with tailwind using the map function

Currently, I am combining tailwind, react, and nextjs to develop a website. My goal is to implement the check radio button technique to dynamically display different content on the website without relying on JavaScript. To streamline data management, I am ...

Are you considering using Amazon cloud services for hosting your website?

Can Amazon ECS be used to host a webpage? I attempted to visit my site , but nothing is displaying. With a username and SSH key provided by my boss, I'm unsure of where to place the index.html file in order for it to appear on the web. Any guidance w ...

Eliminate whitespace on the right side of a webpage using Bootstrap

I am currently working on a form that will appear in a modal, but I need it to be centrally aligned so that I can reduce the size of the modal. Here is what I have implemented so far: It seems like there is some space being "reserved" for columns that are ...