Issue arising with the resizing of the image in the main section, as it is shrinking prematurely before reaching the designated width

Desired Outcome

Current Situation

Currently, I am in the process of creating a responsive hero section where I aim to maintain the image at full size until the window width reaches below 1300px. However, I have observed that the image starts to shrink much earlier than expected, and I am uncertain as to why this behavior is occurring.

Below are snippets of my HTML and CSS code:

/* *************** */
/* HERO-SECTION */
/* *************** */

.hero {
  max-width: 130rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-content: center;
  column-gap: 9.6rem;
}

.hero h1 {
  font-size: 5.2rem;
  font-weight: 700;
  margin-bottom: 3.2rem;
  line-height: 1;
  letter-spacing: -1px;
}

(hero p {
  font-size: 1.8rem;
  font-weight: 500;
  margin-bottom: 4.8rem;
  line-height: 1.5;
}

.btn:link,
.btn:visited {
  font-size: 2rem;
  padding: 1.2rem 3.2rem;
  text-decoration: none;
  display: inline-block;
  background-color: #e67e22;
  color: white;
  border-radius: 1.5rem;
  font-weight: 500;
  transition: all 0.3s;
}

.left:hover,
.left:active {
  background-color: #cf711f;
}

.right:link,
.right:visited {
  background-color: white;
  color: #333;
  margin-left: 2.4rem;
}

.right:hover,
.right:active {
  background-color: #fdf2e9;
  color: #333;
  box-shadow: 0 0 0 3px white;
}

.hero-section {
  background-color: #fdf2e9;
  padding: 16rem 32rem;
}

.head-img {
  width: 100%;
}

.deliver-ithems {
  display: flex;
  align-items: center;
  margin-top: 8rem;
  gap: 1.6rem;
}

.deliver-imgs {
  display: flex;
}

deliver-imgs img {
  height: 4.8rem;
  width: 4.8rem;
  border-radius: 50%;
  border: #fff solid 2px;
  margin-left: -1.6rem;
}

.deliver-imgs img:first-child {
  margin: 0;
}

.deliver-text {
  font-size: 1.8rem;
  font-weight: 600;
}

.deliver-ithems span {
  color: #cf711f;
}
<header class="hero-section">
  <div id="hero">
    <div class="head-text">
      <div class="text-section">
        <h1>
          A healthy meal delivered to your door every single day
        </h1>
        <p>
          The smart 365-days-per-year food subscription that will make you eat healthy again. Tailored to your personal tastes and nutritional needs.
        </p>
        <a href="#" class="btn left">Start eating well</a>
        <a href="#" class="btn right">Learn more &darr;</a>
        <div class="deliver-ithems">
          <div class="deliver-imgs">
            <img src="img/customers/customer-1.jpg" alt="customer" />
            <img src="img/customers/customer-2.jpg" alt="customer" />
            <img src="img/customers/customer-3.jpg" alt="customer" />
            <img src="img/customers/customer-4.jpg" alt="customer" />
            <img src="img/customers/customer-5.jpg" alt="customer" />
            <img src="img/customers/customer-6.jpg" alt="customer" />
          </div>
          <div class="deliver-text">
            <span>250,000+</span> meals delivered last year
          </div>
        </div>
      </div>
    </div>
    <div class="img-hero">
      <img src="hero.png" alt="three images" class="head-img" />
    </div>
  </div>
</header>

I have tested with standard widths, but the issue persists. I believe I have followed best practices, yet the desired result eludes me.

Answer №1

You have the option to specify a pixel value for the width of the .head-img image instead of using 100%. By utilizing media queries, you can adjust the width when the device reaches a width of 1300px.

Take a look at how I implemented this:

/* *************** */
/* HERO-SECTION */
/* *************** */

.hero {
    max-width: 130rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    justify-content: center;
    column-gap: 9.6rem;
}

.hero h1 {
    font-size: 5.2rem;
    font-weight: 700;
    margin-bottom: 3.2rem;
    line-height: 1;
    letter-spacing: -1px;
}

.hero p {
    font-size: 1.8rem;
    font-weight: 500;
    margin-bottom: 4.8rem;
    line-height: 1.5;
}
// Continue with the CSS code from the original text...

@media screen and (max-width: 1300px) {
    .head-img {
        width: 400px;
    }
}

Check out the result here: https://i.sstatic.net/GkKCTCQE.png

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

To view the following set of three images, simply click on the "load more" button

I'm looking to add a load more button to reveal additional images. Currently, the page loads with 3 images visible, and upon clicking the load more button, the next set of 3 images should be displayed on the screen. Unfortunately, the code I've ...

Place an image in the middle of a div

Here are a few images for you to consider: <div class="builder-item-content row"> <div class="twelve columns b0" style="text-align:center;"> <ul class="upcoming-events"> <li> <a href="http://www.padi.com/scub ...

Leveraging the browser's built-in validation error messages in Angular for HTML forms

Is there a way to incorporate browser's native HTML validation error messages into Angular applications? https://i.sstatic.net/J0em4.png What I am looking for is the ability to leverage the built-in error messages when working with reactive forms li ...

Unable to utilize the full column space provided by bootstrap

I need assistance in making three buttons span the entire width of a column. The grid consists of 3 sections for the buttons and 9 sections for other components. Here's a visual reference. Essentially, the buttons should take up the space highlighte ...

How to automatically switch to the next tab in Bootstrap using JQuery when the video finishes

I recently developed a tabbing system featuring 4 tabs using Bootstrap. While it currently functions manually, I am seeking a way to have it loop automatically upon video completion. Below is my current code: <div id="tab"> <ul class="nav nav ...

What are some creative ways to enhance the appearance of a deactivated radio button?

In a table cell, I have a set of radio buttons with a background color that differs from the rest of the page. At times, based on another input, I need to disable certain radio buttons. When a radio button is disabled, its interior color blends with the t ...

Tips on applying a class to a host element using @hostbinding in Angular 2

I've been wanting to assign a class to the host element of my component, and initially I used the host property in this manner: @Component({ selector: 'left-bar', host: { 'class': 'left-bar' }, templateUrl: 'a ...

Implementing a permanent class following an incident

Is it possible to dynamically add a class to an element when an event occurs rather than based on a condition? For example, I have a td that displays a variable. <td>{{myVar}}</td>//myVar=10 When the variable changes to myVar=15, I want to ad ...

assistance in incorporating CSS classes using jQuery

In an attempt to modify the bottom border color of my navigation bar based on the link being hovered over, I want the bottom border color to change to match that of the hovered link. When the link loses focus or hover, the navigation bottom-border should r ...

Displaying videos in full screen using HTML5

I am attempting to create a fullscreen webpage with a video using the following code: <video id="backgroundvideo" autoplay controls> <source src="{% path video, 'reference' %}" type="video/mp4"> </video> ...

Connecting Angular TextArea functionality to the Ctrl-Enter keyboard shortcut

Recently, I've been working on creating a custom functionality for the <textarea> element. My goal is to have the enter key trigger a specific function, while using ctrl+enter will add a new line in the textarea. I've tried looking through ...

textarea label align: center

I've been struggling to center-align the label for this textarea within the text box, but so far my attempts have failed. The resulting display resembles the following: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxx ...

Is there a way to stop a nested table from causing the parent table to expand?

This is where I'm demonstrating the issue: https://jsfiddle.net/ahnfcwdo/1/ Below is the structure of the table: table { max-width:100%; overflow: auto; } .table1 { border: 1px solid red; } .table2 { border: 1px solid blue; ...

"Creating a link to a button with the type of 'submit' in HTML - a step-by-step

Found the solution on this interesting page: In a list, there's a button: <form> <ul> <li> <a href="account.html" class="button"> <button type="submit">Submit</button> ...

JavaScript does not alter the text box for the default dropdown value

My webpage has three elements: a text box named txtSubTotal, a drop-down menu named discount, and another text box called txtGrossTotal. The txtSubTotal updates when the user clicks on the 'ADD' button, while the txtGrossTotal updates based on th ...

After loading ajax content onto the page, the scroll bars fail to appear

I am currently constructing a website that loads page content through ajax. Everything seems to be functioning perfectly, except for a peculiar issue I have encountered in Chrome and Safari. Surprisingly, it is working flawlessly in IE! The problem lies i ...

Conflict between jquery and hoverIntent libraries

I've encountered an issue with a website that was functioning properly until we added a new form to a specific page. The form, created by another person, utilizes javascript/jQuery for processing. Since adding this form, it has caused the majority of ...

Expanding canvas due to the utilization of column-count

I am currently working with chart.js and have a setup that includes two pie charts and a bar chart that I would like to display in a single row. In order to achieve this layout where the bar chart is larger than the pie charts, I implemented the following ...

Two different background colors adorn the Table and Body, adding a touch of visual

Hi everyone, I have a basic question regarding the styling of a webpage. I want the body of the page to have one color while having the table in the center with a different color. I've tried specifying different colors for the body and table in CSS, b ...

Problem with incorporating responsive gifs

I'm new to CSS and I'm trying to incorporate an animated GIF as a smartphone screen using Bootstrap to ensure responsiveness. I've managed to get it working for larger and medium screens, but the issue arises when resizing for smaller displa ...