Guidelines for positioning images next to each other with HTML and CSS

I am struggling to figure out a way to display three images on my webpage with text descriptions below them, followed by another set of three images with text descriptions underneath those. I want to achieve this using only HTML and CSS without relying on Flexbox.

So far, I have been able to align all six images in a vertical column on the left side of my page. However, I have tried various methods like floating, using display properties, or CSS grid, but nothing seems to give me the desired layout.

If anyone has any suggestions or solutions to help me achieve this layout, I would greatly appreciate it! Thank you.

Answer №1

To achieve this layout, you can utilize the power of CSS grid as you mentioned. By using the grid-template-columns property, you can specify how you want your columns to appear.

In the example below, I have set up 3 columns with each taking up equal space (1fr per column). This layout is ideal for showcasing an image along with some accompanying text.

While there are various methods to achieve a similar result, leveraging CSS grid proves to be very effective in scenarios like these. Additionally, applying a media query on the .grid class allows you to adjust the layout, such as switching to a block display for mobile devices if needed:

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

.child {
  padding: 10px;
}

img {
  width: 200px;
  height: auto;
}
<div class="grid">
  <div class="child">
    <img src="https://example.com/image1.jpg" alt="Image 1" />
    <p>Description 1</p>
  </div>
  <div class="child">
    <img src="https://example.com/image2.jpg" alt="Image 2" />
    <p>Description 2</p>
  </div>
  <div class="child">
    <img src="https://example.com/image3.jpg" alt="Image 3" />
    <p>Description 3</p>
  </div>
</div>

Answer №2

If you want to arrange the images in a horizontal row, you can follow this example:

<div class="row">
  <div class="column">
    <img src="img_beach.jpg" alt="Beach" style="width:100%">
  </div>
  <div class="column">
    <img src="img_desert.jpg" alt="Desert" style="width:100%">
  </div>
  <div class="column">
    <img src="img_city.jpg" alt="City" style="width:100%">
  </div>
</div>

<style>
   .column {
     float: left;
     width: 33.33%;
     padding: 5px;
   }
</style>

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

Style binding for background image can utilize computed properties or data for dynamic rendering

In my code, I am trying to pass an object that contains a string path for its background image. I have experimented with using data and computed properties, but so far I haven't had any luck getting them to work within the :style binding. However, if ...

Responsive CSS Dropdown Menu - Divided into Two Columns

After searching for solutions in the support resources and experimenting with various techniques, I am struggling to divide this CSS Dropdown menu into two columns. The nav list is long enough that it extends below the fold. Although the menu adapts respo ...

Exploring anchor hover effects and navigating adjacent sibling elements

Consider this html structure: <p><a></a></p> <div><a><img></a></div> To hide all images inside a div after a p tag, you can use the following code: p + div {display:none;} However, attempting to sho ...

Transforming the indicator of the React responsive carousel to full-width rectangles

I am working on customizing the indicators to appear rectangular and cover the full width based on the length of the images, similar to this example: https://i.sstatic.net/j4yov.png However, I am currently facing an issue where the divs are always displa ...

Utilize XQuery to manipulate both outer elements and inner elements

As a newcomer to XQuery, I am seeking assistance with the following XML example: <lg> <l n="1">Z nutz vnd heylsamer ler / verma⸗ </l> <l n="2">nung vnd ervolgung der wyßheit / ver </l> <l n="3"> ...

Create partial form copies dynamically based on user selections within a nested form

Attempting to design a form that dynamically generates copies of a nested form based on user input. Three models are involved: Visualizations, Rows, and Panes. The goal is to enable users to select from a dropdown menu, create a row, and choose 1, 2, or 3 ...

JavaScript random number functionality experiencing an unexpected problem

function generateRandomNumbers(){ var max = document.getElementById('max').value; var min = document.getElementById('min').value; var reps = document.getElementById('reps').value; var i; for (i=0; i<reps ...

When working with HTML entities, it decodes the ampersand symbol as &

Currently, I am developing a website using ASP.NET MVC which supports multiple languages. Whenever I try to input &#233; to display the character é, it ends up converting it to &amp;#233;. It appears that the system is automatically converting & ...

Selenium struggles to locate elements within Iframes even when they are clearly visible

My current project involves developing code to automatically log into the Life is Feudal game website in order to gather specific information. This information is legally accessible manually, but it would be extremely time-consuming to collect everything w ...

What are some ways to customize the text and button location for Bootstrap 5's file input?

Bootstrap 5's input type file seems too simplistic. Check it out here https://i.stack.imgur.com/VZ0h5.png I am curious about three things: Can the "Choose file" button be moved to the right? Is it possible to change the message that says "No files ...

Tips for designing a unique CSS ellipse effect for text styling

Hey there! I have a list of titles in a drop-down menu as strings, for example: "Bharat Untitled offer #564", "Bharat Untitled offer #563" The titles are quite long, so we want to display the first eight characters, followed by '...' and then ...

A beginner's guide to implementing the GET method with Express.js

Hey there, I have a folder named "vehicles" on my PC and I'm looking to set up a localhost to generate links for each image in that folder. For example: localhost:800/vehicle/ So when I click on the link, it should display the image. However, bein ...

Positioning a file drop area discreetly hidden behind a cluttered data-packed table

I have been experimenting with the ngx-file-drop module for Angular 4. Lately, I have been working on adding a file drop feature to a website that displays data in a table using *ngFor and *ngIf directives. My goal was to create a background drop zone beh ...

What is the code to automatically change the selected input radio button every 3 seconds?

I am attempting to cycle between different input radio buttons being checked every 3 seconds in my Next.js project. The switching works from case0 to case1 and case1 to case2, but not from case2 back to case0. My React and Next.js knowledge is at an inte ...

Adjust color scheme of drop-down menu

Having trouble changing the background color for my drop down menu. I tried to change the color for the sub div but it's not working. Can anyone help me fix this issue? Here is the code snippet: http://jsfiddle.net/3VBQ6/4/ #nav li:hover ul.sub li { ...

Enhance your form input-group in Bootstrap-4 by adding a stylish border and background-color through validation

I'm working on a form using Bootstrap 4 and I need to display validation errors. Specifically, I want the text field with an input-group for the password to have the same styling as the Username field when there is an error (i.e., red border and backg ...

Create a visual representation using a push button

Hey there, I'm attempting to create an image using a button on canvas. However, I'm facing an issue where I can't draw on the clear canvas. Here's my code: <!doctype html> <html> <head> <meta charset="utf-8"> ...

Switching between different alert classes in Bootstrap 4 can cause the alert type to malfunction

I am in the process of developing an alert system for a web application using Bootstrap 4. Below is the code I have implemented: function bsalert(str1, str2) { $(".alert").addClass('show'); $(".alert").addClass('alert-'+str ...

Develop a unique CSS class tailored for a single screen within the Bootstrap framework

I recently created a custom CSS class with a font-size property of 2.9vw. It works perfectly on small screens (sm), but appears too large on medium (md) or large (lg) screens. I prefer not to use media queries as I want this to be handled within Bootstra ...

Is it possible to define a multiplication margin using css?

I am trying to place a box in the center of a container, but I am unable to set a static height for the parent element as it may change. This is causing issues with aligning the box perfectly in the middle of the page. Any assistance would be greatly app ...