Excessive grid image spills over surrounding elements

Here are the code snippets. Everything seems fine here, but in my browser, the last image overflows on the blue section and the text below it is not visible at all. This issue occurs with the third list item of the unordered list.

/****************
Custom CSS Styles
****************/

body {
  margin: 0;
  text-align: center;
}

img {
  display: block;
  width: 100%;
  height: auto;
}

h1, h2 {
  margin: 0;
  padding: 10px 0;

}

p {
  margin: 0;
  padding: 10px 10px;
}
li {
  list-style: none;
}

.btn {
  background-color: #e3e3e3;
  text-decoration: none;
  padding: 3px 5px;
  border 1px solid black;
}

/*****************
SHOWCASE STYLES
*****************/

#showcase {
  min-height: 400px;
  color: white;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8>";
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="reset.css" type="text/css">
  <link rel="stylesheet" href="responsivegrif.css" type="text/css">
  <title>Responsive Grid Layout</title>
</head>
<body>
  <div id="showcase" class="grid">
    <div class="image">
        <div class="backimage"></div>
    </div>
    <div class="showcasecontent">

        <div class="welcome">
          <h1>Welcome To My Responsive Website</h1>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Autem pariatur, esse accusamus quis magni eveniet est veritatis asperiores temporibus iusto laborum illo eos doloremque dolorum corporis aut in nostrum sapiente.</p>
          <a class="btn" href="#">Read more</a>
        </div>

    </div>
    </div>

Hey everyone, I'm currently working on a responsive page using CSS grid. However, one of the images is overflowing beyond its container. I have applied the grid class to this section, but the last image within the list item is still causing overflow.

<div class="section-b grid">
<ul>
  <li>
    <div class="li">
      <img src="item-1-image.jpeg" alt="">
    </div>
    <div class="licontent">
      <h2>Section B Item 1</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut doloribus, magni vitae odio doloremque facilis laborum cupiditate ut tempore quaerat.</p>
    </div>
  </li>
  <li>
    <div class="li">
      <img src="item-2-image.jpeg" alt="">
    </div>
    <div class="licontent">
      <h2>Section B Item 2</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eaque, aliquid. Tempora voluptas necessitatibus aut repudiandae eum incidunt adipisci animi laudantium.</p>
    </div>
  </li>
  <li>
    <div class="li">
      <img src="item-3-image.jpeg" alt="">
    </div>
    <div class="licontent">
      <h2>Section B Item 3</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Esse ratione odio nulla, iste error impedit itaque. Saepe unde, consectetur impedit.</p>
    </div>
  </li>
</ul>

Additional CSS:

@media (min-width:700px) {.grid {display: grid;}}

Answer №1

For those using Bootstrap, try incorporating the "img-responsive" class within the img tag. If not, you can add the class "img-responsive" in your CSS file.

Custom CSS

.img-responsive{
display: block;
    width: 100% \9;
    max-width: 100%;
    height: auto;
}

HTML Example

<img class="img-responsive" src="https://farm1.staticflickr.com/1/2759520_6dea8b9007.jpg" alt="Greece-1173 - Temple of Athena by Dennis Jarvis, on Flickr">

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

Error: jQuery is unable to access the property 'xxx' because it is undefined

While attempting to make a post request from the site to the server with user input data, I encountered an error message saying TypeError: Cannot read property 'vehicle' of undefined as the response. Here is the HTML and script data: <!DOCTY ...

Is there a way to modify AJAX response HTML and seamlessly proceed with replacement using jQuery?

I am working on an AJAX function that retrieves new HTML content and updates the form data in response.html. However, there is a specific attribute that needs to be modified before the replacement can occur. Despite my best efforts, I have been struggling ...

Trouble arises as the Raspberry Pi GPIO pins refuse to toggle

Encountering an intriguing issue here. I've developed a Python program to regulate the climate of a room with a web interface. While the program functions properly, upon restarting the Raspberry Pi, all GPIO pins are activated. It's only after ac ...

What is the best way to position the navbar above all the other text content?

I'm experiencing an issue where the navbar is not appearing on top of all the text/buttons. How can I adjust it so that the navbar appears on top? Thank you. https://i.sstatic.net/59M2l.png [Codepen](https://codepen.io/turbo0/pen/NWBMNQr) ...

"Enhance your web development skills by mastering jQuery alongside the

It's curious that jQuery doesn't support the use of the "+" sign. You can see how it functions with "1" and "3", but not with "2+". Just hover your mouse over each div to experience it. <div id="div-2+"></div> JSFiddle $('a. ...

Exploring the archive of content with AJAX back button tracking

Greetings, Before considering this question as a duplicate, I would like to mention that I have thoroughly searched for similar questions but none of them address my specific issue. Below is a simple example, and any assistance you can provide would be hig ...

Elevate your design game by mastering CSS transformations for precise element

I am trying to center a div with a variable width using the following code: div { background: red; max-width: 400px; position: absolute; left: 50%; transform: translateX(-50%); } Check out my demo here While this code works well for centering, ...

What is the reason for the gap between the bottom row and the one above it?

Using bootstrap to create a table and my code is as follows: <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> ...

Start a server without the need to access it through a web browser

On my back-end server (PHP 7.2), I am calling a .php file from index.html every few seconds. <!DOCTYPE html> <html> <head> <title>Title of the document</title> <script src="https://ajax.googleapis.com/ajax/libs/jqu ...

Drawing intersecting lines on a javascript canvas and clearing them using the lineto method

I am working with a canvas where lines are drawn based on mouse movement. I am trying to achieve the effect of the line only lasting for a few seconds before disappearing, similar to swirling a ribbon with a set length. I have been using lineTo to draw the ...

The sticky position is failing to function properly when I set the float property to the left on other

I noticed that the position sticky for the header stops working once I add float:left to another element. The tricky part is, if I remove the float:left from main>div, the sticky header works fine. Despite my efforts to find a solution through Google, n ...

How can a block be made to stay fixed and float in a flexbox layout?

There are three blocks within the body of this page. Title bar Content block Bottom block I have employed a flex display for the body layout. My goal is to make the title bar float, meaning it should always remain at the top when scrolling. I attempted ...

Is there a way to insert a record upon the user clicking on the Add Record button?

// Here is my Component code // I want to figure out how to add a new row to the table with fresh values. import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-uom', templateUrl: './uom.component.html ...

Bootstrap4 navigation bar featuring a collapsible centered logo and two rows for enhanced functionality

Can you help me customize my Navbar for a 2-row layout? CompanyLogo link link link ----------------------------------------------------------------------- link(dropdown) link link link lin ...

The name 'Landbot' cannot be located. Have you meant to type '_landbot' instead?

I'm currently in the process of integrating Landbot into my React.js application with TypeScript. I'm following this [doc] 1. However, I'm facing an issue where the code inside useEffect (new Landbot.Container) is causing an error. 'C ...

The feature of Jquery click and cursor: pointer only focuses on a single element at a

Recently, I created a navbar that includes a dropdown feature. I encountered an issue where I wanted the dropdown to show up when clicking on the navbar-profile class (which contains the profile picture, name, and chevron icon) in the top right corner. Ho ...

Is there a unique shape element, such as a true circle, available in HTML5?

There doesn't seem to be any documentation on this, suggesting they may not exist. However, it's always worth investigating. I am in search of a perfectly circular (or any polygon shape other than a rectangle) element. I can create a circle in c ...

Utilizing JavaScript to display numerous variables within a text box

After creating an HTML form, I encountered an issue where only one selected item was displayed in the text field. Can anyone help me solve this problem so that multiple names can be printed in the textfield? function myFun(extras) { document.get ...

Issue specific to iOS devices: AJAX-loaded HTML containing <script> tags fails to execute

The purpose of the code below is to import innerStuff.html into the content-container div. Once that is done, a script within innerStuff.html named submit_entry() is used to submit the form in innerStuff.html. Current Situation: Upon clicking the button, ...

What is the best way to create a shape using CSS?

In my chat application, I have a functionality where replies on a chat are initially hidden and represented by a count in a red box. When the user clicks on the red button, the replies from other users are revealed along with an input box for writing a r ...