What steps can I take to revert the image back to its original size?

I'm trying to create a gallery, but the images are too zoomed in. How can I make them fit properly?

I've experimented with adjusting the width and height, but it's not quite right.

Here is the HTML code:

<div class="bod">    
    <h1 class="header1">Gallery</h1>
        <div class="wrapper-gallery">
            <div class="media">
                <div class="layer">
                    <p class="para">Student: RANDOM</p>
                </div>
                <img src="https://images.unsplash.com/photo-1431818563807-927945852ab6?dpr=1&auto=format&fit=crop&w=1199&h=899&q=80&cs=tinysrgb&crop=" alt="" />
            </div>
         <div class="media">
            <div class="layer">
                <p class="para">Student: RANDOM</p>
            </div>
            <img src="https://images.unsplash.com/photo-1431818563807-927945852ab6... crop=" alt="" />
          </div>
          <div class="media">
            <div class="layer">
                <p class="para">Student: RANDOM</p>
            </div>
            <img src="https://images.unsplash.com/photo-1431818563807-927945852ab6...tiny... alt=""/>
          </div>
        </div>
      </div>
 </div>

Check out the CSS for the above:

<style>
    @import url('https://fonts.googleapis.com/css?family=Inconsolata|Source+Sans+Pro:200,300,400,600');

.bod {
  height: 100vh;
  display: flex;
  width: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #E0E0E0;
  overflow: hidden;
}

.header1 {
  font-family: 'Source Sans Pro', sans-serif;
  font-size: 22px;
  color: #151E3F;
  font-weight: 300;
  letter-spacing: 2px;
}

.wrapper-gallery {
  display: flex;
  justify-content: center;
  align-items: center;
  > * {
    margin: 5px;
  }
}

.media {
  width: 300px;
  height: 200px;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  img {
      max-width: 100%;
      height: auto;
    }
}

.layer {
  opacity: 0;
  position: absolute;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 10px;
  height: 90%;
  background: #FFF;
  color: #151E3F;
  transition: all 0.9s ease;
  p {
    transition: all 0.9s ease;
    transform: scale(0.2)
  }
}

.para {
  font-family: 'Inconsolata', monospace;
  text-align: center;
  font-size: 15px;
  letter-spacing:1px;
  font-size: 15px;
}

.media:hover .layer {
  opacity: 0.8;
  width: 95%;
  transition: all 0.5s ease;
  p {
    transform: scale(1);
    transition: all 0.9s ease;
  }
}

@media (max-width: 800px){
  .bod {
    transform: scale(0.8);
  }
}

@media (max-width: 600px) {
    .wrapper-gallery {
    display: block;
    > * {
      margin: 10px;
    }
  }
</style>

The issue is that the images are zoomed in too close. Does anyone know how to make them fit snugly?

Answer №1

@azametzin, it seems like you have placed the img element incorrectly within the layer.

The issue lies in the CSS for .media, and it appears to be invalid, especially in Chrome browser.

A correct implementation would resemble this:

.media {
  width: 300px;
  height: 200px;
  overflow: hidden;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.media img {
  max-width: 100%;
  height: auto;
}

Answer №2

To adjust the size of the images, make sure to include width: 100% in the CSS for the img element. This will allow them to adapt to the width of their parent element.

img {
  width: 100%;
}

Alternatively, you can use background-image instead of img:

<div class="image" style="background-image: url('site.com/nice-image.png')</div>

.image {
   background-size: cover;
   background-position: center;
}

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

What is the best way to adjust my CSS so that the height of my textarea always mirrors the height of its parent div?

My goal is to have a textarea adjust its height to match the height of the containing div. Currently, the width is perfect, but the empty textbox only takes up around 20% of the div's height. Even when text is added via an ajax call, the textarea rem ...

Displaying a variable in a text box using the italicized format

Could you please share how to display a variable in a textbox using italics style? Appreciate your help! ...

Eliminating Redundant CSS Code Using PHP Storm

After upgrading to PHP Storm version 8.03, I came across an article that discussed the ability to search for duplicate CSS code using this link: . Although I have tried to find a way to automatically resolve these duplicate codes within PHP Storm, I have ...

What is the best way to showcase information after a specified period?

Is there a way to make a div container appear after a specific time period, let's say 10 seconds? I am using a CLASS instead of an ID. I attempted the following: $(document).ready(function() { $(".contentPost").delay(5000).fadeIn(500); }); As ...

Tips for preventing a bootstrap card image from overflowing in the card-body

I'm currently working with bootstrap cards and I've been able to prevent the card image from overflowing outside of the card area. However, I'm facing an issue where the bottom of the image overflows into the card-body region. I'm not s ...

What could be causing my button to not smoothly navigate to its designated section in Bootstrap 4?

I'm in need of assistance with implementing scrollspy functionality, including a button within the navbar that jumps to a specific section. I tried enhancing semantics by using an anchor tag and placing it next to the navbar links using a form-inline ...

Tips for enabling an item to be moved around using HTML?

How can HTML be utilized to create a draggable item without simply assigning it as draggable? ...

The HTML table seems to be inexplicably replicating defaultValue values

I'm encountering an issue where, when I use JavaScript to add a new table data cell (td), it ends up copying the defaultValue and innerText of the previous td in the new cell. This is confusing to me because I am simply adding a new HTML element that ...

Set a variable equal to the innerHTML

Although I am not very familiar with JavaScript, I am looking to generate HTML table TD elements dynamically using JavaScript. Unfortunately, the code I have written is not functioning correctly. <script type="text/javascript"> function changed(num) ...

Ways to update modal content upon clicking a button

I have a scenario where I need to display 2 modals (box1 and box2) in my code with box2 appearing on top of box1. Each modal has its own button, and I want to make sure that box1 appears first. Then, when the user clicks the button in box1, it transitions ...

Adjust the image's alignment to the center within the <li> tag

Welcome to my website! Visit to learn more. I am looking to center align the banner on the homepage. Here's a snippet of my HTML: <div id="contentmain"> <div class="bannerarea"> <div class="slideShow"> <ul cla ...

Having issues with displaying options in Select2 within a Vue Component?

I have successfully created a Vue component that generates options for a select dropdown as shown below: <select ref="subdomain_id" name="subdomain_id" id="newEvidenceSubdomain" class="form-control" :class=&qu ...

From PHP to Drupal Node with HTML transformations

Currently, I am developing a custom module on Drupal. Within this module, I have a requirement where users should be able to upload a PDF file. Once uploaded, the module should create a Node of type 'decision.' In the 'field_decision_text&ap ...

Having trouble getting event modifiers to work in Vue when added programmatically

Trying to dynamically add events using v-on through passing an object with event names as keys and handlers as values. It appears that this method does not support or recognize event modifiers such as: v-on=“{‘keydown.enter.prevent’: handler}” T ...

Why is Selectpicker (bootstrap-select) not functioning properly and displaying a disabled menu?

Currently, I am attempting to implement the selectpicker feature from Bootstrap-Select in order to create a dropdown menu that supports multiple selections. Below is the snippet of code that I have included in my HTML file: <select class="selectpicker" ...

When additional form elements are introduced following the execution of an AJAX and PHP script, they fail to get transferred

Utilizing AJAX to retrieve the selected element value from a dropdown menu and triggering a PHP script to generate input checkbox fields. Here is an overview: HTML <form method="post" action="liens_chra.php" name="Form" id="Form"> <label f ...

What is the best way to obtain the inner ID with JQuery?

How can I assign values to inside id using JQuery? Sample code from controller.cs: public GroupModel Get() { IGroupTypeRepository groupTypeRepo = new GroupTypeRepository(); IGroupRepository groupRepo = new GroupRepository(); var model = new ...

Click on the live view area in Adobe Brackets to quickly jump to the corresponding code segment

Is it possible to have brackets highlight the associated code when clicking on an area in the live view? For instance, if I click on an image in the live view, can brackets take me directly to the img tag of that picture? ...

Can Javascript be used to identify the number of td elements in a table and specify column widths within the table tags?

Is there a way to automatically add the "col width" tag based on the number of td tags within a Table tag? For example, if there are 2 td's, then it should add 2 "col width", and if there are 3 then, 3 "col width", and so on. <!DOCTYPE html> &l ...

Attempting to configure the <img> element to automatically adjust its size in accordance with the page dimensions

<center> <img style="width: 100%; max-height: 100%" src="images/ratios/3to2ratio.JPG" /> This is a traditional 35mm Still Film ratio of 3:2. </center> Although this code allows the image to scale with the page size, I prefer ...