How come my CSS is causing my images to not align horizontally?

Hey there, I'm facing an issue with the layout of 6 images on my website. Currently, they are stacked vertically, but I want them to be displayed horizontally and centered. Additionally, 4 of these images have captions that should appear below each image. Could someone please assist me with this? Thank you!

Below is my HTML:

  
  <div class="container-fluid">

    <div class="container-of-images">
      <img src="chick2.png">

      <figure>
        <img id="img1" src="dice6.png">
        <figcaption>Testing</figcaption>
      </figure>

      <figure>
        <img id="img2" src="dice6.png">
        <figcaption>Testing</figcaption>
      </figure>

      <figure>
        <img id="img3" class="threeChoices" src="dice6.png">
        <figcaption>Testing</figcaption>
      </figure>

      <figure>
        <img id="img4" class="fourChoices" src="dice6.png">
        <figcaption>Testing</figcaption>
      </figure>
      <img src="chick1.png">
    </div>
  </div>

And here is my CSS:

body {
  background-color: #b6e6bd;
  line-height: 1.6;
}

.container-fluid {
  padding: 1% 20%;
  margin: auto;
  text-align: center;
}

img {
  width: 100px;
  line-height: 0;
  margin: 0 1%;
  display: flex;
  justify-content: center;
}

figcaption {
  text-align: center;
  width: 100px;
}

https://i.sstatic.net/sMoIS.png

Answer №1

Here is a solution using CSS code to address the issue. The main problem was that 'display: inline-block' should have been utilized instead of 'flex'.

 

        body {
            background-color: #b6e6bd;
            line-height: 1.6;
        }

        .container-fluid {
            margin: auto;
            text-align: center;
            width:100%;
        }

        img {
            width: 100px;
            line-height: 0;
            margin: 0 1%;
            display: inline-block;
            justify-content: center;
            vertical-align: middle;
        }

        figcaption {
            text-align:
                center;
            width: 100px;
        }

        figure {
            display: inline-block;vertical-align: middle;
        }
    

Answer №2

Set your image holder as a flex item that organizes the elements horizontally:

.image-wrapper {
    display: flex;
    flex-flow: row nowrap;
    justify-content: center;
    align-items: center;
}

Answer №3

To fix the issue, make sure to include either 'display: inline;' or 'display: inline-block;' in your CSS code.

body {
  background-color: #b6e6bd;
  line-height: 1.6;
}

.container-fluid {
  padding: 1% 20%;
  margin: auto;
  text-align: center;
}

img {
  width: 100px;
  line-height: 0;
  margin: 0 1%;
  display: inline;
}

figcaption {
  text-align: center;
  width: 100px;
}

Answer №4

Have you experimented with implementing flexbox on the main container? Give this a shot:

.image-container {
    display: flex;
}

Answer №5

To resolve the issue, include the CSS property display:flex in the container-of-images class. However, keep in mind the importance of responsive design when making this adjustment.

.container-of-images {
    display: flex;
    flex-direction: row; /* Using flex alone can help resolve the problem */
    justify-content: space-around; /* Adding this line will space the images around */
}

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

Is there a way to execute JavaScript code before any other scripts on the page? I need to perform a session check in JavaScript that redirects to a different page

My website has session and JavaScript checks to see if it exists. Everything is working correctly, but there is a slight issue where the dashboard page briefly appears for milliseconds before redirecting. I need the webpage to redirect before any HTML co ...

The placeholder text is not displaying with bullets in Internet Explorer. However, it is functioning correctly in Chrome

I need assistance displaying the placeholder text in IE8 as shown below: "Any relevant reference numbers, such as Direct Debits: - Name of the Branch (if applicable) - What was the original problem - Date the problem occurred " While it appears correct ...

JavaScript enables the deletion of a class

In HTML 2, I am able to show different statements based on the scenario. These statements are styled using the Bootstrap alert class. The goal is to ensure that when new data is sent, any old communication disappears without causing overload on the page. ...

Harvesting the local image file

Currently, I have implemented a form that allows users to upload images and crop them. The process flow has been established as follows: 1. User uploads the image 2. Server processes the image and sends it back to the browser 3. User crops the image a ...

Incorporating SASS/SCSS syntax within the <style> element

Can I include SASS/SCSS syntax directly in an .html file within a style tag? I'm interested in defining a variable within the .html file and then utilizing it in a .sass file. ...

Attempting to repair navigation menu on grou.ps website

Hey there, I'm currently working on improving the appearance of my website. The original site can be found at . After integrating it with the grou.ps community platform, I noticed that the navigation menu is not displaying correctly and the image is ...

What is the best way to arrange form inputs in a single row?

My form consists of three input boxes. While the first two inputs are single line, the third is a description field with 10 rows set as default. However, for some reason, this third box is not aligned properly with the other two. Please refer to the screen ...

Expandable menu featuring visual icons and a toggle symbol

I am in need of assistance to implement an accordion menu with unique picture icons for each item on the left and a toggle icon (such as + or a chevron) on the right side. Visually, I would like it to resemble this design (https://codepen.io/kathykato/pen ...

Inverting the hierarchy of a tree structure

I am currently working with a tree structure and utilizing the jstree jQuery plugin. My main objective is to reverse the structure. https://i.sstatic.net/PG1Ha.png The desired structure should resemble the one shown in this image. I have made modificatio ...

Progress Bars Installation

For more detailed information, visit: https://github.com/rstacruz/nprogress After linking the provided .js and .css files to my main html file, I am instructed to "Simply call start() and done() to control the progress bar." NProgress.start(); NProgress. ...

Position a dynamically generated cell in the middle of the window

I am currently developing an employee directory that allows users to search for a specific employee and view their information in a tree or org-chart layout. To achieve this, I have implemented the Google Org Chart code for generating the chart. Each emplo ...

What is the best way to ensure the edit form displays in the correct location?

My attempt to have this edit form displayed upon clicking the edit button using AJAX jQuery was successful. However, the form does not appear in the correct position. Here is an image before clicking the edit button: https://i.sstatic.net/8l3t6.jpg And ...

Troubleshooting problem with iPhone X responsiveness

Struggling with responsive issues on iPhone X. Issue is only appearing on actual device. Any tips for fixing this? I'm facing an issue where the website looks good and responsive on all devices in Chrome's responsive view. But when I access it th ...

Problems arising from the layout of the PrimeNG DataView component when used alongside Prime

I've been working with a PrimeNG DataView component that requires the use of PrimeFlex's flex grid CSS classes to set up the grid structure. One of their examples includes the following instructions: When in grid mode, the ng-template element ...

Bizarre glitch with input box on PC using Safari

Within my HTML5 game, there is an input box that I need to be functional on both mobile and PC devices. To achieve this, I have included both mobile jQuery and PC jQuery simultaneously. <input id="searcher" data-role="none" type="search" placeholder="S ...

Reposition icons to the center within the icon-div container

I am trying to center align the elements in my icon-div as shown in the wireframe image. What steps should I take to achieve this layout? HTML: <div class="icons_div"> <div class="row bg-secondary"> <div class="col-sm-2"> ...

Tips for adjusting the dimensions of material table within a react application

Could someone please provide guidance on adjusting the size of a table made with material table? I am currently working in React and the following code is not yielding the desired outcome. I even attempted to use 'react-virtualized-auto-sizer' wi ...

FireFox - Dynamic Blinking Divs on Hover

It seems like in FireFox and IE, my hover effect is blinking for some reason. I can't figure out why this is happening. Should I switch to using JavaScript for my hovers or is there an easier CSS solution? Here's a JSFiddle link to demonstrate th ...

Using Bootstrap, Express, and Node.js to create a login form

As I am new to node.js and express, I am still trying to understand the basic functionality. Currently, I have a simple sign-in form where I want to load another HTML page and call a node.js function upon clicking the sign-in button. What would be the best ...

Struggling with integrating Bootstrap into a Vue.js application due to a compatibility problem with

I am facing difficulties importing Bootstrap features such as modal in a Vue component that uses installed packages like bootstrap, popper.js, and jquery. I am working with nuxtjs for this project. Unfortunately, when trying to import these features, I en ...