Learn the technique for showcasing images side by side in HTML

As I delve into the realm of HTML, I'm encountering some challenges that are leaving me scratching my head. My goal is to have three images aligned in a row horizontally, like this: | img 1 | img 2 | img 3 |. The outer div container I'm working with has sufficient space to accommodate all three images.

I've experimented with various methods such as inline-block, inline, and float, but none seem to produce the desired outcome.

This is what I currently have:

<div id="banner" style="overflow: hidden; display: inline-block;">
    <div class="" style="max-width: 20%; max-height: 20%;">
        <img src ="img1.jpg">
    </div>

    <div class="" style="max-width: 100%; max-height: 100%;">
        <img src ="img2.jpg">
    </div>

    <div class="" style="max-width: 20%; max-height: 20%;">
        <img src ="img3.jpg">
    </div>
</div>

Answer №1

To ensure proper alignment, make sure to set the inner divs to display inline-block instead of the outer one.

  <div id="banner">
    <div class="inline-block">
        <img src ="img1.jpg">
    </div>

    <div class="inline-block">
        <img src ="img2.jpg">
    </div>

    <div class="inline-block">
        <img src ="img3.jpg">
    </div>
</div>

I have removed the inline CSS in favor of using a separate external stylesheet. I used "inline-block" as a sample class name, but feel free to rename it as needed.

In your CSS file, you can define the style for the class like this:

.inline-block {
   display: inline-block;
}

I have also provided a functional fiddle showcasing three images displayed side by side: https://jsfiddle.net/3m33emfd/

Remember that the parent container, #banner, should not be set to inline-block. It serves as an outer wrapper for the child divs and should have display: block applied. This adjustment has been made in the working fiddle example.

Answer №2

try using display:inline-block; for this layout.

    <div id="banner" style="overflow: hidden;justify-content:space-around;">
    <div class="" style="max-width: 20%;max-height: 20%;display: inline-block;">
        <img src="img1.jpg">
    </div>

    <div class="" style="max-width: 100%;max-height: 100%;display: inline-block;">
        <img src="img2.jpg">
    </div>

    <div class="" style="max-width: 20%;max-height: 20%;display: inline-block;">
        <img src="img3.jpg">
    </div>
    </div>

Answer №3

Here is the CSS code provided:

display: flex; justify-content: space-around;

<div id="banner" style="overflow: hidden; display: flex; justify-content: space-around;">
        <div class="" style="max-width: 20%; max-height: 20%;">
            <img src ="img1.jpg">
        </div>

        <div class="" style="max-width: 100%; max-height: 100%;">
            <img src ="img2.jpg">
        </div>

        <div class="" style="max-width: 20%; max-height: 20%;">
            <img src ="img3.jpg">
        </div>
    </div>

Answer №4

Enclose the images with img tags to directly apply the style without using any div elements. Like so:

<img style="max-width:20%" src="…">

Answer №5

.image-div{
  float:left;
  margin-right:10px;
  max-width: 20%;
  max-height: 20%;
}
<div id="banner" style="overflow: hidden; ">
  <div class="image-div" >
    <img src ="img1.jpg">
  </div>

  <div class="image-div" >
    <img src ="img2.jpg">
  </div>

  <div class="image-div" >
    <img src ="img3.jpg">
  </div>
  <div style="clear:left;"></div>
</div>

Answer №6

<!DOCTYPE html>
<html lang="en">
<head>

<title>Contemporary Gallery </title>



<style>
.image {
display: inline-block;
}

</style>

</head>

<body>
   <div id="banner" style="overflow: hidden; display: inline-block;">
        <div class="image" style="max-width: 20%; max-height: 20%;">
            <img src ="pic1.jpg">
        </div>

        <div class="image" style="max-width: 100%; max-height: 100%;">
            <img src ="pic2.jpg">
        </div>

        <div class="image" style="max-width: 20%; max-height: 20%;">
            <img src ="pic3.jpg">
        </div>
    </div>


    </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

Issue with form submissions when loading it through ng-view

After setting up the AngularJS file to load the view upon clicking the 'add item' button in the navigation bar, I encountered an issue where submitting the form did nothing. However, when I loaded the PHP file separately, it worked seamlessly and ...

Tips for displaying Modal Bootstrap at the bottom of the screen

Is there a way to configure Bootstrap so that the modal appears at the bottom of the browser? https://jsfiddle.net/9fg7jsu3/ <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Modal test</button& ...

Looking to showcase image captions at the bottom of the viewport instead of the bottom of the page

I am looking to center the captions of each image at the bottom of the viewport, so that they stay in the same place when a user scrolls (on hover). Sorry if this layout is incorrect, I'm still new to coding. I wasn't able to link the actual ima ...

Passing a variable using a button's value attribute in jQuery

My goal is to develop a form in my application where users can input their name and address. Once the user enters the information, I need to validate it and add it to an array before submitting it to the PHP function. Additionally, I want to provide users ...

Accessing a unique URL from within the form_valid function of a Django class-based view

Have you ever tried the HTML trick that lets you trigger the phone's native SMS app by clicking a link? For example, if you use <a href="sms:14085551212?body=Hello my friend">New SMS Message</a>, clicking on New SMS Message will open the S ...

Guide to retrieving the promise outcome from HTML using Vuejs

I am currently working on a Vuejs website for a university project. The main goal of the function is to determine whether a particular book has been marked as a favorite and then return the name of the corresponding icon so it can be displayed correctly ...

Dealing with the challenge of line breaks across different browsers: Showing content retrieved from an ajax request in a

This file contains text with line breaks: https://i.sstatic.net/n8tSh.png To display the text in a textarea, I'm using the following style: textarea.journalctl{ width: 640px; height: 620px; white-space: nowrap; } Chrome ...

I am in need of setting up two rows side by side using the display

I'm trying to have two rows side by side using display grid, but I'm facing some issues. When I use the following CSS... .grid-container { display: grid; grid-template-rows: auto auto; grid-template-columns: auto; grid-column-gap: 100px;} It cre ...

Top tip for handling repetitive code with echo commands

I've been struggling with a question for quite some time now. Imagine you have a code that consists of multiple nested divs and spans, forming a square with an image inside. echo '<div> <div> <div> <div> <span> < ...

Implementing a feature where a button is included within a table to delete an object from

Tasked with creating a form and an empty table, I need to utilize the DOM to generate a new object from the class Movie and insert it into the table. Additionally, I must include a button that allows users to remove the movie entry. However, I am unsure ...

creating a wide div using bootstrap 4

Why is the bottom border not extending the full width within the inner div? <div class="container-fluid"> <div class="row"> <div class="col-12 col-md-2 bg-light mh-100"> <div class="d-flex jus ...

Restrict the input to only allow for parentheses, disallowing any letters or numerical characters

Only parentheses are allowed in the input field; letters and numbers will not be accepted. function checkBrackets() { var inputVal = document.getElementById("input").value; var result = document.getElementById("strong").value; console.log(inputVal, ...

Adjust the dimensions of the text area to modify its height and width

Can someone help me adjust the width and height of the <textarea> tag in HTML so that it only has two lines (rows)? Right now, it's only displaying one line. Any suggestions on how to solve this issue? Even when I try changing the width to 1000 ...

Angular 6 - Unlocking the Secrets of Filtered Results

I need help accessing the filteredArray in my .ts component. Currently, it is only accessible within the ng-container. <ng-container *ngIf="(userList | filter: 'name' : value) as filteredArray"> <tr *ngFor="let user of filteredArray ...

JavaScript and HTML: Importing local JSON and considering module accessibility

My journey with javascript / html is just beginning, and I find myself struggling to grasp the import / module functionality. My current challenge involves loading a json file into javascript. After some research, I came across using import as the best wa ...

There seems to be an issue with Jekyll where it is failing to generate HTML for Markdown pages

I recently delved into the world of Jekyll to transfer my blog over to GitHub Pages. Utilizing a local Jekyll tool (jekyll 3.1.3) with the neo-hpstr-jekyll-theme as a starting template on my Windows system. While the entry point (index.html in root) and p ...

Identify Bootstrap modal to modify destination of keypress input

I am working on a piece of code that detects keypress events and focuses input towards a searchbar with the id "search". $( document ).keypress(function() { $("#search").focus(); In addition, I have a bootstrap modal dialog containing input fields ...

Are You Able to Develop a Floating Window That Stays Persistent in JavaScript?

Looking to create a persistent floating window in a NextJS 14 app. This window needs to remain on top, even when navigating between browser windows. Want it to stay visible even when the browser window is minimized, like a Picture-In-Picture feature. Mos ...

Manipulating class properties in AngularJS from a controller

I won't dwell on the reason for this (it's required to override some behavior in Angular Material that is causing issues in Safari), but here is what I am attempting to accomplish: HTML: <style> .changeme{ height: 300px; } </st ...

Position two elements next to each other in a fluid/responsive manner with an unspecified width

I have recently been assigned a React project for my Full-Stack position at work. Within a wrapper div, there are 2 nested divs. Here's the breakdown of these divs: Left Div - Contains text within a span, with ellipsis and hidden overflow, allowin ...