What is the best way to ensure that three images stretching across the entire width of the website are responsive?

I am looking to showcase 3 images across the full width of my website, with each image taking up one-third of the space. I want these images to be responsive and adjust accordingly to different screen sizes while maintaining their aspect ratio. Do you have any suggestions on how I can achieve this?

Currently, I've been able to implement this design, but I'm facing issues with the images shrinking in an unnatural way when the site is scaled down.

https://i.sstatic.net/kXVAo.jpg

Here's the code snippet that I've used so far:

#content {
  height: auto;
  width: 100%;
  font-size: 0px;
  display: flex;
}

.images {
  width: 33.33%;
  height: 800px;
}
<div id="content">
  <img src="images/phantom.png" class="images" alt="Image of an actor from the musical Phantom of the Opera">
  <img src="images/lion_king.png" class="images" alt="Image of an actor from the musical Lion King">
  <img src="images/wicked.png" class="images" alt="Image of an actor from the musical Wicked">
</div>

Answer №1

It seems like you are close to the solution! Try wrapping the images in a div and then setting the flex-basis of those divs to one third using calc(). Make sure to also set (max-)width:100% for the img elements.

UPDATE - Original Poster's feedback

You're on the right track, but the heights of the images are uneven and causing alignment issues with the footer. Any suggestions on how to fix this?

Since your images have different aspect ratios, try adding display:flex to the parent div.

body {
  margin: 0
}

#content {
  height: auto;
  width: 100%;
  display: flex;
}

#content>div {
  flex: 0 calc(100%/3);
  display: flex;
  /*demo*/
  box-sizing: border-box;
  border: 2px solid red
}

img {
  width: 100%;
  display: block
}
<div id="content">
  <div>
    <img src="//placehold.it/300x800" class="images" alt="Image of an actor from the musical Phantom of the Opera"> </div>
  <div>
    <img src="//placehold.it/300x800" class="images" alt="Image of an actor from the musical Lion King">
  </div>
  <div>
    <img src="//placehold.it/300x800" class="images" alt="Image of an actor from the musical Wicked"></div>
</div>

Answer №2

Place the images in a container element and adjust their size using either width: 100% or max-width: 100%.

#gallery {
    height: auto;
    width: 100%;
    font-size: 0px;
    display: flex;
}

.photos {
    width: 100%;
}
<div id="gallery">
  <div>
    <img src="http://example.com/image1.jpg" class="photos" alt="Description of Image 1">
  </div>
  <div>
    <img src="http://example.com/image2.jpg" class="photos" alt="Description of Image 2">
  </div>
  <div>
    <img src="http://example.com/image3.jpg" class="photos" alt="Description of Image 3">
  </div>
</div>

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

Reset input fields upon jQuery removal

Currently, I am working on a form that includes a remove function. The function is functioning correctly, but I am facing an issue where I want the field values to be cleared when the remove function is triggered. This is necessary as I am sending input va ...

Mootools tweening color transition denied for child elements when color is explicitly defined in CSS

Check out this link for testing: http://jsfiddle.net/EnJSM/ You might observe that by removing "color: #6CB5FF;", the transition behaves differently - it only works for the second part of the line. I'm interested to see what solution you come up wit ...

JQuery table sorter is unable to effectively sort tables with date range strings

I am facing an issue with sorting a column in my table that contains text with varying dates. The text format is as follows: Requested Statement 7/1/2014 - 9/16/2014 When using tablesorter, the sorting does not work properly for this column. You can see ...

Is it possible to create an animation with CSS3 transitions?

Experience a dynamic blinking border animation when hovering over the title: #link_list a:hover { border-left: 10px solid #E3E3E3; animation: blink 1s infinite; -webkit-animation: blink 1s infinite; -moz-animation: blink 1s infinite; -o-animation: blink 1 ...

Leveraging the power of animate.css library to enhance page transitions on Nuxt

I've been working on implementing the animate.css library for nuxt page transitions, but I'm encountering some issues. I have successfully added animate.css to the nuxt.config.js file and it loads without any problems. However, when I try to use ...

Changing Tailwind CSS variables for customization

Using Variables in index.css : :root { --property: 1; } A Different Approach to Changing it with CSS on Hover: img{ transform: scale(var(--property));; } .another-element:has(:hover, :focus) { --property: 1.1; } There's a way to inclu ...

The Analog Clock is unable to access the property of null

I'm struggling to understand what's wrong here. The querySelector doesn't seem to be functioning correctly as I keep encountering the error "cannot read the property of null" on line 10 of my JavaScript code. const deg = 6; const hr = docum ...

In what way does Angular incorporate _page-theme.scss assets?

The Angular Material Documentation homepage includes a specific scss file: https://github.com/angular/material.angular.io/blob/master/src/app/pages/homepage/_homepage-theme.scss Although this scss file is not directly imported into the component's ...

Prioritize the Menu display

Is there a way to bring the menu's black background in front of the body text in the image below? Here is the JSFiddle link for reference: https://jsfiddle.net/johnking/j58cubux/6/ The issue occurs when scrolling down and the menu is not clearly vi ...

Use an if-else statement in jQuery with selectors to determine if a specific div element has been added to it

What if you have a main div and append one of these sub-divs to it? For example: <div class ="append"> <div id ="one"></div> <div id ="two"></div> </div> Then in jQuery, could you do something like this: if ($(.a ...

Is it possible to open a new tab window using a radio button?

Looking for assistance with radio buttons. I want users to be redirected to a new window when they click the submit button beneath the radio buttons. If anyone has a solution, please help! I have tried using window.location.href and window.open but the c ...

transferring data from an HTML form on the View page to the controller

I am currently working with the MVC framework. Within my project, I have a View named view1 which contains an HTML Form outlined below: <form action='/Exercise/Exercise4_SubmitForm' method="post"> Name: <input type="text" name=" ...

The minimum height increases as the inner divs expand

Can you help me with the code below? html <div class="content"> <div class="col"> </div> <div class="col"> </div> <div class="col"> </div> <div class="col"> </div> ...

Bootstrap's landing page problem

I am currently working on creating a landing page using bootstrap and have encountered an issue with the text alignment in my section containing icons and tags. In order to make the text appear clean and concise, I want the text to be displayed in either o ...

Can a custom CSS be linked directly to the angular-cli.json file?

I'm trying to incorporate custom CSS into my angular-cli.json file, but I haven't been able to find a successful method. I attempted to use the following code: "styles": [ "styles.css", "http://site.test/mycss.css" ], However, it does ...

I am having trouble accessing the database. Jacky @ localhost Password: NO

https://i.sstatic.net/7Kvfu.png What is preventing me from accessing the database? Username: jacky @ local host Password: NO ...

A guide to toggling the check/uncheck status of a list box by clicking on a checkbox using

I am using a div and CSS id to control the checkbox check and uncheck functionality, but I am not getting the desired outcome from my source code Step 1: By default, the checkbox is unchecked and the listbox is disabled Step 2: When the checkbox is check ...

Expansive image coverage

My footer design includes a rounded left image, a repeating middle section, and a rounded right image. How can I ensure that it scales perfectly responsively without overlapping? Ideally, the solution would involve adjusting the width of the middle section ...

What is the best way to access the inner html of every cell within a table row that I have selected?

I want to implement a feature on my website where users can click a "save" button on a specific row in a table and save the entire row's innerHtml onto another page as their favorite hiking trails. I've been trying to achieve this by adding clic ...

How to Position Buttons at the Bottom of a Card with Bootstrap

When creating a card for certain items, I am using the code below. To align the button at the bottom of the card, I have implemented the following: return ' <div class="col"> <div class="card detail ...