Utilizing Flexbox for Arranging Content within a Container in HTML and CSS

I am currently working on getting the images to display within a pre-designed box that I set up. However, the images are appearing too wide and extending beyond the 50em width of the box. Additionally, they seem quite large in terms of height, and I'm unsure if this is simply due to the image size or an issue with the code. I am utilizing flexbox for this layout.

Currently, when there are no images present, it appears as though they are all in a single line due to the wrapping, but once the images are added, the layout starts to malfunction.

main{
    width:50em;
    border-style:solid;
    display:flex;
}

.images{
    display: flex;
    flex-direction: row;
    flex: 1 1 25em;
    flex-wrap: wrap;
    flex-grow: 1;
}
<!DOCTYPE html>
<html>

<head>
    <!-- A meta element naming the Unicode character set you want the browser to use (UTF-8). -->
    <meta charset="UTF-8">
    <!-- A link to reset -->
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
    <link rel="stylesheet" href="flex.css">
</head>
    
<body>
    <main class="wrapper">
        
        <header id="images">
            <img src="student-misc-02.jpg" alt="student1">
            <img src="student-misc-06.jpg" alt="student1">
            <img src="student-misc-08.jpg" alt="student1">
            <img src="student-misc-12.jpg" alt="student1">
            <img src="student-misc-19.jpg" alt="student1">
            <img src="student-misc-20.jpg" alt="student1">
        </header>    
        
    </main>
    
</body>

</html>

Answer №1

I have successfully adjusted the CSS code to align with your HTML code. Additionally, some of your revisions displayed as three columns; the latest CSS rule aims to recreate that three-column layout.

main {
  width: 50em;
  border-style: solid;
  display: flex;
}

/* Corrected the selector to match your html code using id instead of class */
#images {
  display: flex;
  flex-direction: row;
  flex: 1 1 25rem;
  flex-wrap: wrap;
  flex-grow: 1;
}

/* If you require the three columns as in your initial query */
#images img {
  width: 33%; 
  margin: auto;
}
<!DOCTYPE html>
<html>

<head>
  <!-- A meta element specifying the Unicode character set for the browser (UTF-8). -->
  <meta charset="UTF-8">
  <!-- Link to reset stylesheet -->
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
  <link rel="stylesheet" href="flex.css">
</head>

<body>
  <main class="wrapper">

    <header id="images">
      <img src="http://lorempixel.com/400/200" alt="student1">
      <img src="http://lorempixel.com/400/200" alt="student1">
      <img src="http://lorempixel.com/400/200" alt="student1">
      <img src="http://lorempixel.com/400/200" alt="student1">
      <img src="http://lorempixel.com/400/200" alt="student1">
      <img src="http://lorempixel.com/400/200" alt="student1">
    </header>

    <section class="title">
      <!--<h1>XD Rountable 2019 Event Calendar</h1>-->
    </section>

    <footer>
    </footer>

  </main>

</body>

</html>

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

Displaying special characters in an HTML TextArea

I am facing an issue with displaying a particular character on a textarea: … My website is set to UTF-8 encoding, including the meta header and file encoding. The database, table, and fields are all in UTF-8 as well, since it is the default encoding. I ...

Having trouble incorporating an external CSS stylesheet into my Angular 9 project

I'm a beginner to Angular and I wanted to incorporate W3 CSS into my project. Here are the steps I took: Installed W3 CSS using npm in my project directory by running: npm install --save w3-css Added node_modules/w3-css/w3.css to angular.json "st ...

How come an <a> tag is nabbing mouse clicks from a <canvas> element?

I have been experimenting with creating a 3D piano using three.js. Here is a snippet of the code I am currently working on: let renderer, camera, scene, light, keys, selectedKey; init(); render(); function init() { // Code for initializing renderer, ...

Automatically redirect to the linked page once the video concludes

Would it be feasible for a html5 video to trigger the opening of a new page upon completion? What would be the approach to achieve this using javascript? ...

Is it possible to establish a connection between Firebase Storage and HTML using TypeScript without Angular or React in IntelliJ?

My project goal is to create a functional login and register page using TypeScript. Currently, my code operates without a database, but I aim to implement Firebase for registering user credentials for easy login. I have only come across tutorials using F ...

What is the best way to change the height of this menu bar?

I have a stylish menu that suits my website perfectly. However, when I add this menu to my page, I am struggling to make it fill the vertical length of the page (it is already vertical but not very long). The only solution I have found is to adjust the le ...

Safari does not consistently display uniform button height with the use of flex alignment

Within the div I have a button enclosed in the following structure: HTML: <div class="parent-container"> <div class="child child-1 col-xs-6"> <button class="btn btn-primary">Customize Feed</button> </div> ...

When scrolling, the menu is being overlapped by the Carousel in HTML5, CSS3, and

I am currently working on a One Page HTML webpage that needs to be responsive, and the requirement is to use Bootstrap. I have gone through all the tags but can't seem to identify the issue. One problem I encountered is that when I scroll down the pa ...

Personalize the appearance of BeautifulSoup's prettify function based on the specified tag

Is there a way to customize the prettify function to prevent it from adding new lines to specific tags? I want to keep span and a tags from splitting up, like this: doc="""<div><div><span>a</span><span>b</sp ...

What is the best way to retain changes made to a checkbox that is used for email notifications?

Users on my website receive email notifications when someone comments on their profile or blog. To give users control over these notifications, I have created an email settings page with checkboxes that allow them to choose whether or not they want to rece ...

Hovering over and leaving a child submenu with a mouse

Here is a menu that I created using ul element: <ul class="offerings"> <li><a>NO SubMenu</a></li> <li><a>With SubMenu</a> <ul id="submenu"> <li><a href="">SubMenu 1</ ...

Concealing elements such as buttons, icons, and text dynamically with AngularJS depending on screen resolution

I have mastered responsive html using Bootstrap, but now I need to dynamically remove elements based on screen resolution. Let's compare browser view versus mobile view: https://i.sstatic.net/q53aa.jpg Depending on the resolution, certain buttons s ...

Can the recaptcha icon be customized with a new hue?

I have been attempting to alter the captcha icon/logo in recaptcha v2. Initially, I tried to modify it using regular CSS without success. Then, I experimented with jQuery to determine if the iframe had loaded completely before proceeding with the change. ...

Is it possible for a typo3 website to automatically redirect users to a mobile-friendly version?

I have put together a landing page for my website with numerous content elements using only HTML and then pasted it into my typo3 backend. I ended up with separate HTML codes for desktop view and mobile view because I couldn't figure out how to make t ...

The base tag does not impact the <META HTTP-EQUIV="Refresh" element in any way

Similar Question: How to check for disabled JavaScript? I am attempting to identify whether or not JavaScript is disabled in the user's browser. To achieve this, I have inserted an iframe into the document and set it to refresh every 10 seconds. ...

Using Angular 4 constructor value in a condition with *ngIf

Within this TypeScript snippet, there is a variable called moreinfo that is initially set to 1. In the constructor, however, the value of moreinfo is changed to 2. Subsequently, based on whether the value is 1 or 2, different div elements are displayed usi ...

Whenever a JavaScript Ajax Call is made, it consistently returns readyState=1 and status=0

I've been using AJAX to send a post request, but I'm running into some issues. Every time I check the xmlhttp.readyState, it's always coming back as 1 and the xmlhttp.status is always 0. Also, the xmlhttp.responseText is consistently empty. ...

Converting JSON data into an HTML table

I'm struggling to convert a JSON object into an HTML table, but I can't seem to nail the format. DESIRED TABLE FORMAT: Last Year This Year Future Years 45423 36721 873409 CURRENT TABLE FORMAT: Last Year 45423 This ...

Is there a way to include a tag as an argument in a scss mixin?

Currently, I am working on a mixin that will target a specific child element within a parent. For instance, my goal is to target all <a> tags within a parent element that also has a parent of section---blue. I initially thought that passing the tag ...

Addressing a HTML/CSS navigation bar formatting glitch

I have been attempting to replicate the design from , but with the menu positioned at the top of the screen. Despite reviewing tutorials on w3schools and other sources, I am still unable to understand why it is not aligning correctly at the top. Below is t ...