Place a vertical arrangement of images within a horizontal row using flexbox

I am struggling to create a two-column layout with text on the left and a column of images on the right. The images should be the same height as the container and only take up the necessary width. Unfortunately, my attempts with various markup structures, flex attributes, min-heights, and max-content have been unsuccessful. The image column either overflows the container, doesn't shrink to the minimum width needed, or distorts the images.

For reference, please see this simplified example: https://jsfiddle.net/e78hk42v

/* Decoration */

html {
  font-family: Inter, sans-serif;
}

main {
  padding: 20px;
}

aside {
  background: black;
  padding-left: 10px;
}

article {
  border: 10px solid black;
  margin: 0 auto;
  padding: 0;
  /* Define the size of the overall panel */
  display: flex;
  max-width: 600px;
  max-height: 90vh;
}


/* Column of images */

aside>div {
  display: flex;
  flex-direction: column;
  margin-top: -5px;
  margin-bottom: -5px;
}


/* Each image container */


/* More reliable to have containers with half-padding, than apply a margin to bare images */

figure {
  margin: 0;
  padding-top: 5px;
  padding-bottom: 5px;
}

img {
  display: block;
  max-width: 100%;
}
<article>
  <main>
    <p>Hello hello hello hello</p>
  </main>

  <aside>
    <div>
      <figure>
        <img src="https://picsum.photos/800/500" alt="">
      </figure>
      <figure>
        <img src="https://picsum.photos/800/500" alt="">
      </figure>
      <figure>
        <img src="https://picsum.photos/800/500" alt="">
      </figure>
    </div>
  </aside>
</article>

Does anyone have any suggestions on how to style this layout so that the images column fits within the container and uses the minimum horizontal space while preserving the image aspect ratio?

Answer №1

Adjust the styling to

aside > div { height: 100%; display: grid; grid-template-rows: repeat(3, 1fr); }
.
Also include
img { width: 100%; height: 100%; object-fit: cover; }
. Here is a sample implementation:

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

article {
  --gap: 10px;
  border: var(--gap) solid black;
  margin: 0 auto;
  padding: 0;
  display: flex;
  max-width: 600px;
  max-height: 90vh;
}

main {
  padding: 20px;
}

aside {
  display: flex;
  flex-direction: column;
  padding-left: var(--gap);
  background: black;
}

aside > div {
  height: 100%;
  display: grid;
  gap: var(--gap);
  grid-template-rows: repeat(3, 1fr);
}

figure {
  min-height:0;
}

img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
<article>
  <main>
    <p>Hello hello hello hello</p>
  </main>
  
  <aside>
    <div>
      <figure>
        <img src="https://picsum.photos/800/500" alt="">
      </figure>
      <figure>
        <img src="https://picsum.photos/800/500" alt="">
      </figure>
      <figure>
        <img src="https://picsum.photos/800/500" alt="">
      </figure>
    </div>
  </aside>
</article>

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

The button in Bootstrap 4 that triggers the modal stays in a highlighted or clicked state even after the modal has been

I am currently utilizing the button below to trigger the opening of a modal window However, upon closing the modal, it seems to maintain a highlighted or clicked appearance with a shadow effect. Initially, I assumed I could address this issue by implement ...

Unbelievable attribute: sup causing peculiar styling in link element

We've recently come across an issue where the text-decoration of an underline in an anchor tag appears strange when there is a sup element present. The visual glitch looks like this: https://i.sstatic.net/X2Yqg.png For reference, here's the HTML ...

Is there a way to set it up so that clicking on a small image will automatically switch to the corresponding larger size image?

For instance, I have 4 small images and 1 main image. When I click on a small image, the main image changes to display that selected picture. I was wondering if there is a specific value to place inside target=""? I prefer to only use HTML/CSS as I am no ...

Adjusting distinct column widths based on categoryID

Is there a way to assign different CategoryIDs (1, 2, and 3) based on certain conditions and work with varying column widths within <div class="Meta1">? I need to add 2 more CategoryIDs. Any suggestions on how to achieve this? Thank you. if ($ ...

Achieving centered text alignment in a span using Bootstrap 5

I am facing an issue with a span in an input group that has a minimum width of 6rem. This is causing the text to not be centered, as spans typically adjust to the width of the text itself. .input-group-text { min-width: 6rem; } <link rel="stylesheet ...

The height of my "img" element is not being fully matched by my "a" tag

As part of a project redesigning the Kurzgesagt home page, I encountered a challenge when trying to make my a tag stretch the full height of my img. The a tag was wrapping the img in the HTML code. Below is the code I used: HTML <a href="http://kurzg ...

The div above the footer seems to be interfering with the styling of the footer. Is there a solution to

I am currently working on implementing a Help functionality for our users. In order to do this, I have placed a div right above my footer. However, I am facing an issue where the styling of my div is affecting the footer in ways that I cannot figure out. ...

How to vertically center align h1 using Bootstrap

<body> <nav class="navbar navbar-expand-md bg-dark navbar-dark py-3"> <div class="container"> <div class="navbar-brand mx-auto"><h2 style="color: white;">Name< ...

What is the best way to ensure a textarea element fills the entire height using Bootstrap 4?

Is there a way to ensure the textarea element dynamically adjusts its height to fill the space between the header and footer without causing a scroll bar when using bootstrap 4? Here is the HTML code snippet I've been working with: #container { ...

Struggling to create a mobile-friendly design

I've successfully created a dynamic world map using D3.js, but I need some guidance on making it responsive across various screen sizes. You can view the interactive world map here. Credentials to access the map: Username: DXLdemo Password: ...

Customizing Styles in Material UI with React

I am facing an issue with customizing the styles in my Material UI theme in React. Specifically, I am trying to modify the border of the columnsContainer but it doesn't seem to work, only the root style is having an effect. Take a look at this Codesa ...

What is the best way to trigger an onclick event for an input element with a type of "image"?

In the code I'm working on, there's an input of type "Image". <div class="icon" id="button_dictionary"> <form> <input class="buttonDictionary" type="image" src="icone_dicionario.jpg" value="" id="inputDictionary"> ...

Accessing the clandestine div via direct hyperlink

I have incorporated a toggle plugin from this website to display hidden divs. Each hidden div is identified by a unique id. Is there a method to show a specific div using a direct link? For instance, by entering domain.com/page.php#HiddenDiv2, it should ...

Effortlessly Styling Children Elements in Emotion JS When Parent Element is Hovered

This particular query seems to have been posed and resolved in various ways, but the solutions I've come across either do not pertain to Emotion or the responses related to Emotion haven't yielded results for me. I am currently using @emtion/[ema ...

Blurring a section of a circular image using a combination of CSS and JavaScript

I'm trying to achieve a specific effect with my circular image and overlaying div. I want the overlaying div to only partially shade out the image based on a certain degree value. For example, if I specify 100 degrees, I only want 260 degrees of the c ...

Get the value of a CSS property in Python by parsing the rendered HTML

Currently, I am using Selenium and PhantomJS in conjunction with Python for the purpose of crawling rendered web pages. While it is a straightforward process to identify the presence of specific words within the HTML content (e.g. if "example" in html...), ...

Exploring the CSS scale transformation alongside the Javascript offsetHeight attribute

After combining offsetHeight with scale transformation, I experienced a strange result. Below is my simple HTML code: <body> <div id="id01"> Some Text </div> <div id="id02" style="transform-origin: left top; transf ...

Is a CSS-only autoexpanding label possible within a list?

I am interested in having all the labels automatically expand to the size of the widest one. Below is the HTML structure: <div class="body"> <ul class="list"> <li> <span> <label>condition</label> ...

The CSS effect fails to take effect following an AJAX response

After a successful ajax response, I am attempting to apply a jQuery .css effect. However, it seems that this process is not working as expected because I am trying to retrieve the height of a newly created element and then applying it to another newly crea ...

What is the process behind managing today's Google image of the day?

After coming across the javascript picture control on the Google search page, I became interested in replicating it myself. The feature zooms in on a picture when hovering over it, but I couldn't locate the HTML code they were using for it. Is there ...