What causes the container's height to remain unchanged despite changes in the height of its image content?

When I set the height of an image to 50%, its container's height remains the same instead of automatically adjusting.

HTML:

<section class="img-show">

        <div class="img-container">
            <ul>
                <li class="img-item">
                    <a href="">
                        <img src="./AnimatedFrameSlideshow_Featured.jpg" alt="">
                    </a>
                </li>
                <li class="img-item">
                    <a href="">
                        <img src="./DecorativeLetterEffects_featured.jpg" alt="">
                    </a>
                </li>
            </ul>
        </div>
    </section>

CSS:

.img-show {
    width: 100%;
    overflow: hidden;
}
.img-container {
    width: 400%;
}
.img-show ul {
    display: flex;
    padding: 0;
}
.img-item {
    list-style: none;
    width: 100%;
}
.img-item img {
    min-width: 100%;
    height: 50%;
}

Even after applying these codes, the img element changes its height to 50%, but the height of img-show remains constant and is filled with blank space. Any assistance or clarification on this issue would be highly appreciated. Thank you!

Answer №1

When the height of your image is set to 50% of its parent element, it means that the container holding the image must be at least twice as tall as the image itself. This results in the lower half of the container being empty or blank.

In simple terms, the height of the container is determined by the height of its contents. If the height of the image was based on the height of its container, it would create a circular definition. To avoid this, web browsers use the image's width and intrinsic aspect ratio to calculate the 100% height of the image, then adjust the image's height accordingly based on the specified percentage value. This means that no matter what percentage is set for the image's height, the container will always end up being the same height as the image.

Answer №2

It seems like you're unsure about the specific requirements for setting height and width in your code. Based on the information provided in the documentation, both the height and width of an img tag should be directly specified within the tag itself. For example, if you want to display a 50x50 image, you would include the dimensions like this:

<img alt="" height="50" width="50" />

I hope this clarifies things for you.

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

Adjusting the height of a row in Bootstrap can sometimes result in column content overflowing

.row-2 { padding: 20px; margin: 100px auto; box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px; border-radius: 10px; height: 300px; } .fa-solid { ...

Step-by-step guide to adding a skew overlay to your video

I am experimenting with creating a skewed overlay on a video playing in the background at full width. Currently, the skew overlay is functioning perfectly. What if I want it to appear in the bottom-right corner instead of the top-left corner? Would I need ...

Sending information from a dynamic table to a database using PHP

I've created an HTML webpage with a table that fetches data from my database. Each row in the table has a button that, when clicked, dynamically adds the data into another table on the webpage using JavaScript. The dynamic table includes a submit butt ...

Pass a variable between popup.js and background.js in a Chrome Extension

Despite finding some answers to similar questions, none of them provide a complete solution. The information in the answers lacks necessary documents that were not included in the original question. My goal is to create a scaffold for Chrome extensions wh ...

When the form is submitted, I am unable to record the checkbox value

Hi, I have a question regarding submitting a form to the "/delete" route when a checkbox is checked. Although I am able to submit the form successfully, I am facing an issue retrieving the checkbox value that I assigned using ejs. Below are the relevant co ...

Issue with JQuery on Mobile Devices: Troubles with Dropdown Menu and Loading Function

Having some trouble with my JQuery code on mobile devices. The drop down menu isn't showing up on an iPhone, the load function isn't working to display the additional PHP page on a Samsung Edge 7, and the drop down doesn't seem to be functio ...

Enhancing Your WordPress Menu with Customized Spans

I have a WordPress menu structured like this: <div id="my_custom_class"> <ul class="my_custom_class"> <li class="page_item"><a href="#">page_item</a> <ul class='children'> <li class="page_item chil ...

Does "th:each" assign all attributes to the same column?

Having an issue where the "openhours" from the database are loaded into a view, but all 7 opening hours are listed in the Monday column. Below is the code snippet: (HTML) <div class="table-hover"> <table class="table table-striped table ...

Implementing dynamic styling with Alpine JS when hovering

I am working with 2 color pickers, one for background and one for text. These are connected to the styles of a button <button :style="`background-color: ${bg_colour}; color: ${text_colour};`">TEST BUTTON</button> Everything is funct ...

Positioning custom buttons using CSS and HTML

Need help with centering a button inside a div within a table cell. Is there a way to determine the current size of the hovered-over div and position the button in the middle both vertically and horizontally? https://i.sstatic.net/6NQ9J.jpg I hope you ...

Revise the "Add to Cart" button (form) to make selecting a variant mandatory

At our store, we've noticed that customers often forget to select a size or version before clicking "Add to Cart" on product pages, leading to cart abandonment. We want to add code that prevents the button from working unless a variant has been chosen ...

Is there a way to design a table that is responsive and automatically converts to a list when viewed on a mobile device

I am trying to design a responsive table showcasing artists' names. The goal is to have it look similar to this example: After finding and customizing code for the table, I encountered an issue when the table collapses on mobile view. The invisible e ...

It seems that CSS shadows are working perfectly on Firefox and Chrome, but unfortunately, they are not displaying on

I have encountered an issue where CSS shadows appear fine on Firefox and Chrome, but do not display in Internet Explorer. Below is the code I am using: -moz-box-shadow: 0 0 20px #000; Can anyone provide a solution for this compatibility problem? Thank ...

Using jQuery to append a single AJAX response at a time

I wrote a piece of code that utilizes an ajax request to communicate with json-server, retrieving data which is then displayed in an html div using jquery .html(). The content shown in the div depends on the button clicked by the user. While .append() work ...

The wonders of jQuery popup windows

A code was discovered that displays a popup, but it currently relies on transparency (opacity: 0). I would like to modify it to use display: none instead, as the transparent window in the center of my website is causing issues. Here is the JavaScript code ...

Merging HTML Array with jQuery

I am working with input fields of type text in the following code snippet: <input type="text" minlength="1" maxlength="1" class="myinputs" name="myinputs[]" > <input type="text" minlength="1" maxlength="1" class="myinputs" name="myinputs[]" > ...

The background image is failing to display, although other styles for the class or element are visible

Why won't the background image display, even though I have verified that the image path is correct and changing other properties like color or background color works just fine? Here is my CSS code snippet: .container { background-imag ...

Leverage PHP to retrieve information from a JSON file and integrate it into a dropdown menu on an HTML

I've been given a task to develop a PHP routine that will extract the ISO code and name from a geojson file for use in a dropdown list of countries on a website. This is completely new to me and I'm finding it difficult to understand the documen ...

Creating an image using tiles in HTML

I have divided an image into 48 tiles (8x6) using a method similar to "Cutting an Image into 9 pieces C#". Now, I want to reconstruct the original image in HTML. What is the most effective approach to achieve this? Initially, I attempted to use a table wi ...

Challenges arise with the Boostrap grid system, overflow scroll functionality, and responsive design when incorporating specific heights (vh) in elements

Attempting to implement a two-column layout using Bootstrap 4 that incorporates an overflow scroll feature when the height of a parent container is specified. You can view the fiddle here: https://jsfiddle.net/zeropsi/g19kzpsh/ The challenge I'm fac ...