The information presented in the following content seamlessly complements the captivating banner image

I am facing an issue with my banner image that is supposed to display only on small devices in a specified section. For more details, please refer to the following Stackoverflow Topic

However, this setup has caused the content below to overlap and no longer be in sync with the responsive flow based on the height of the banner image.

Here is the code snippet for implementing this:<a href="https://jsbin.com/fekijujuli/1/edit?html,css,output" rel="nofollow noreferrer">JSBin Link</a>

.img-responsive {
  max-width: 100%;
}
        
@media (max-width: 1000px) {
  .cropped {
    position: relative;
    height: 250px;
  }

  .cropped .img-responsive {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    max-width: 150%;
  }
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Website Title Here</title>
   <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cfef3f3e8efe8eefdecdca9b2acb2acb1fef9e8fdad">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
   
</head>
<body>
   <section class="banner">
        <div class="cropped">
            <img src="https://images.unsplash.com/photo-1601134728471-aa7f168d82ed?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=1952&q=80" alt="" class="img-responsive">
        </div>
    </section>
    <nav class="navbar sticky-top navbar-expand-lg navbar-light bg-light">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">Navbar</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
            <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
                <div class="navbar-nav">
                    <a class="nav-link active" aria-current="page" href="#">Home</a>
                    <a class="nav-link" href="#">Features</a>
                    <a class="nav-link" href="#">Pricing</a>
                    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
                </div>
            </div>
        </div>
    </nav>
    <div class="container">
        <div class="row">
            <div class="col-lg-9 mx-lg-auto mt-5 mb-5">
                <h2 class="text-uppercase">
                    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis, dolorum.
                </h2>

                <p class="lead">Lorem ipsum dolor sit amet consectetur adipisicing elit. Sed magni fugiat dolorum! Deserunt velit fuga provident, beatae delectus omnis culpa alias expedita, inventore molestiae aut explicabo? Nihil eum odit saepe voluptatem optio voluptatibus,
                    repudiandae laborum ducimus suscipit eius voluptatum porro debitis fugiat nobis ipsa inventore animi placeat expedita ex sint.</p>

                <p class="lead">Lorem ipsum dolor sit amet consectetur adipisicing elit. Sed magni fugiat dolorum! Deserunt velit fuga provident, beatae delectus omnis culpa alias expedita, inventore molestiae aut explicabo? Nihil eum odit saepe voluptatem optio voluptatibus,
                    repudiandae laborum ducimus suscipit eius voluptatum porro debitis fugiat nobis ipsa inventore animi placeat expedita ex sint.</p>
            </div>
        </div>
    </div> 
</body>
</html>

Answer №1

To enhance the performance of your website, I suggest removing the image from the HTML code and utilizing it as a background image in the CSS style for the container. Here's an example:

.cropped {
            max-width: 100%;
            height: 250px;
            background-image: url(https://images.unsplash.com/photo-1601134728471-aa7f168d82ed?ixlib=rb-1.2.1&ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&auto=format&fit=crop&w=1952&q=80);
            background-position: center; 
        }
        
        @media (max-width: 1000px) {
            .cropped {
                position: relative;
                height: 250px;
            }
            .cropped .img-responsive {
                position: absolute;
                left: 50%;
                transform: translateX(-50%);
                max-width: 150%;
            }
        }
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
   <link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
   
</head>
<body>

  
  
   <section class="banner">
        <div class="cropped">
            <img alt="" class="img-responsive">
        </div>

    </section>


    <nav class="navbar sticky-top navbar-expand-lg navbar-light bg-light">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">Navbar</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
          </button>
            <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
                <div class="navbar-nav">
                    <a class="nav-link active" aria-current="page" href="#">Home</a>
                    <a class="nav-link" href="#">Features</a>
                    <a class="nav-link" href="#">Pricing</a>
                    <a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
                </div>
            </div>
        </div>
    </nav>

    <div class="container">
        <div class="row">
            <div class="col-lg-9 mx-lg-auto mt-5 mb-5">
                <h2 class="text-uppercase">
                    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis, dolorum.
                </h2>

                <p class="lead">Lorem ipsum dolor sit amet consectetur adipisicing elit. Sed magni fugiat dolorum! Deserunt velit fuga provident, beatae delectus omnis culpa alias expedita, inventore molestiae aut explicabo? Nihil eum odit saepe voluptatem optio voluptatibus,
                    repudiandae laborum ducimus suscipit eius voluptatum porro debitis fugiat nobis ipsa inventore animi placeat expedita ex sint.</p>

                <p class="lead">Lorem ipsum dolor sit amet consectetur adipisicing elit. Sed magni fugiat dolorum! Deserunt velit fuga provident, beatae delectus omnis culpa alias expedita, inventore molestiae aut explicabo? Nihil eum odit saepe voluptatem optio voluptatibus,
                    repudiandae laborum ducimus suscipit eius voluptatum porro debitis fugiat nobis ipsa inventore animi placeat expedita ex sint.</p>
            </div>

        </div>
    </div>
  
</body>
</html>

It's worth noting that I have removed the image source from the HTML and instead applied the 'background-image' property to the containing element.

You can experiment with different values for the background image such as 'center'. There are also various other properties associated with background images which you can explore further here.

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

Difficulty in centering certain elements using Bootstrap

I have recently constructed an element for a webpage within the site I am developing. The item is complete, but I am struggling to center it on the page properly. While I can easily center the image, the text associated with it refuses to budge. Here is t ...

determining collisions between the character in my game and a specific block within a 2-dimensional array

Currently, I am working on a fun game project that involves some collision issues. The setup includes a player character drawn on one canvas and blocks (16x16px) drawn on another canvas. However, I am facing difficulties in detecting horizontal collision ...

What is the most effective approach for delivering arguments to event handlers?

Consider the following block of HTML: <button id="follow-user1" class="btnFollow">Follow User1</button> <button id="follow-user2" class="btnFollow">Follow User2</button> <button id="follow-user3" class="btnFollow">Follow User ...

Animating a CSS shape with the .animate method

I need help creating a dynamic graphic for my school project using css, jquery, and html. I want to make a rectangle that moves across the screen, but I'm having trouble getting it to work properly. Despite trying different variations of the animate f ...

Implementing template loading on page load with state in AngularJS

When my application loads, I want the nested view list-patents.htm to be displayed. The main navigation is on my index.htm, featuring two nav items: transactions and patents. If you click on patents, two sub-menu items will appear: list patents and add p ...

The selection choices in the HTML <select> dropdown appear oversized on Chrome browsers

There has been a recent change in Chrome versions, likely in June 2017, that is causing options in a <select> input to appear much larger than in other browsers or older versions of Chrome. For instance, on some machines, the dropdown on this w3scho ...

Centering Slides Vertically in Slick Carousel with Bootstrap 4 Beta

I have spent approximately 2 hours searching and attempting over 15 solutions, but none of them have been successful. The issue involves a slick-slider structured as follows: <section id="testimonial-section" class="pt-4 pb-0 px-4 bg-dark text-white"&g ...

Tips for disabling default browser input validation in React

https://i.stack.imgur.com/834LB.png Is there a way to remove the message "Please fill out this field" while still keeping the "required" attribute intact? I have my own validation system in place, so I need to use the "required" attribute to determine whe ...

Verifying internet connectivity and updating content using jQuery and JavaScript

Upon loading the page, the following functionality occurs without triggering a click event: The updated code attempts to determine if the internet connection is active. If the connection is off, the 'link' on the page will be disabled (non-click ...

jQuery validation for various forms with individual submission buttons

I am working on a single-page application that has multiple forms, such as form_1, form_2, etc., each with its own submit button (submit_1, submit_2, etc.). Each form contains records with checkboxes for taking specific actions and there is also a "select ...

The navigation bar seems to have disappeared from the second page of the website

My navigation bar is working perfectly on my landing page, but when I copied and pasted it onto the second page, it's not showing up. I'm puzzled as to what could be going wrong, as I've checked and rechecked the code multiple times. I have ...

The content within the iframe is not properly sized

I'm facing a challenge with an iframe that has a fixed height of 1000px which I am unable to adjust. I would like the content to fit within the iframe. As a CSS novice, I need some guidance on how to achieve this. Thank you! <iframe style="height: ...

Steer clear of posting additional content that might bump the existing content further up

How can I keep the search bar centered on the screen, even when content is added below it? Here's a screenshot illustrating the issue: https://i.stack.imgur.com/7pQ1q.png The text in the image is causing the search bar to move up, but I want the sea ...

Shake up your background with a random twist

Seeking assistance with customizing the Aerial template from HTML5UP. I am interested in selecting a scrolling background randomly from a pool of images. Can someone guide me on how to achieve this? Presently, the background is defined within a code block ...

Unveil a portal to the identical webpage

My apologies for my English skills... Could anyone advise me on how to display an image? Hello, I am looking for a way to have a small window open on my site when a user clicks on the zoom icon, where I can describe a product. Any guidance on the HTML co ...

unique map customized in a separate browser window

Attempting to complete the code provided here but encountering issues as a novice in java-scripting. It seems like the map is not loading correctly. A new tab and text are generated when DIV is created. Seeking assistance on how to open a custom map in a ...

Display an image when the cursor hovers over a text

I'm attempting to display an image when hovering over specific text. The image should not replace the text, but appear in a different location. The concept is as follows: When hovering over the word "Google", the Google logo should appear in the red ...

What is the best way to compress HTML code within a webpage's source?

I have noticed that my template is filled with empty spaces after previewing the page due to using many tags. Is there a way to make my code more compact, similar to the example below: https://i.sstatic.net/ZBlbg.jpg [...] startsWith",function(a){return ...

Modifying the appearance of the initial column in a panelGrid

Is there a way to left align the first column and right align the second column of a <h:panelGrid>? I've attempted to assign a class to elements in the first column for left alignment, but as they are outputText elements nested in a span inside ...

Set boundaries for the width and height of an image in the input field

Looking to restrict the size of an image in an input field using HTML, CSS, and JavaScript/jQuery. Goal is to maintain a perfect square aspect ratio for profile photo uploads (for example, 200x200 or 300x300). ...