Tips for showcasing the lower portion of a picture

I have created a simple slideshow image div. I want to adjust it to show the bottom of the image instead of the top.

Here is the HTML Code:

<div class="slideshow">
    <div>
        <img src="image1.jpg" />
    </div>
    <div>
        <img src="image2.jpg" />
    </div>
    <div>
        <img src="image3.jpg" />
    </div>
</div>

And here is the JQuery Code:

$(function(){
    $(".slideshow > div:gt(0)").hide();

    setInterval(function(){
        $('.slideshow > div:first')
        .fadeOut(2000)
        .next()
        .fadeIn(2000)
        .end()
        .appendTo('.slideshow');
    }, 8000);
});

Lastly, the CSS Code:

.slideshow {
    position: relative;
    width: 100%;
    max-height: 500px;
}
.slideshow > div {
    position: absolute;
    width: 100%;
    max-height: 500px;
    overflow: hidden;
}
.slideshow > div > img {
    width: 100%;
}

The code works well, but currently only shows the top part of images that are 500px in height. How can we adjust this for images with varying heights?

https://i.sstatic.net/blGrp.png

Answer №1

One easy adjustment is to set the picture as absolutely positioned and attach it to the bottom of the box.

If you decrease the height to 300px, the contrast will be more noticeable in your fiddle example.

.mainImg > div > img {
    width: 100%;
    position: absolute;
    bottom: 0;
}

Answer №2

Give this a shot: https://example.com/code123

Take a look at the first illustration, where an image with greater height displays the bottom-center portion.

$(document).ready(function(){
$(".imageContainer > div:gt(0)").hide();
  
  setInterval(function(){
  $('.imageContainer > div:first')
    .fadeOut(2000)
    .next()
    .fadeIn(2000)
    .end()
    .appendTo('.imageContainer');
  }, 2000);
});
.imageContainer {
  position: relative;
  width:100%;
  max-height: 500px;
  min-height: 500px;
}
.imageContainer > div {
  position: absolute;
  width: 100%;
  max-height: 300px;
  min-height: 300px;
  overflow: hidden;
  /*Delete this line*/
  width: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="imageContainer">
     <div style="background: url('http://www.example.com/image.jpg') no-repeat center">
    </div>
    <div style="background: url('http://www.example.com/another-image.jpg') no-repeat center">
    </div>
    <div style="background: url('http://www.example.com/yet-another-image.jpg') no-repeat center">
    </div>
  </div>

OR

If you prefer, you can also test out this alternative based on Mikael's solution: https://example.com/code456

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

mandatory data fields for an HTML form

I'm having some trouble creating an HTML form with mandatory input fields. The code I have so far is shown below: <div class="col-sm-6"> <label for="city" class="form-control">City ...

What could be causing the response data from an AJAX request to be in error instead of success?

My JSON data is securely stored on , and I can access it through a unique URL. Here is the specific URL: The JSON data found at the above URL is: { "glossary": { "title": "Suyog", "GlossDiv": { ...

Adding information to a designated cell in a table using jQuery

My query is related to jQuery TimeTable. I have set up a table structure like Monday Tuesday ...... continuing till ...

Stop automated web crawlers from crawling through JavaScript links

To enable remote jQuery templating, I have embedded some links in JavaScript. For example: <script type="text/javascript"> var catalog = {}; catalog['key1'] = 'somepath/template_1.html'; catalog['key2'] = 'anotherp ...

Handling Posts and Gets with Jquery/Javascript

Working on a web application that involves generating numerous post and get requests. I am able to monitor all the requests using Developer Tools in Mozilla/Chrome, as well as with Charles (an app). Is it feasible to develop a jQuery or JavaScript functi ...

What are the different ways to position div containers using CSS?

So I have multiple div sections on my webpage, and they are arranged vertically in the following manner: However, I would like them to appear more like this: This is the structure of my HTML: <div id="main"> <div id="header"> ...

The Navbar in Bootstrap 3 remains expanded and does not collapse

It seems like there's a simple solution I'm overlooking. When I resize my screen, the navbar collapse toggle stops working. I've searched various forums but couldn't find a fix that works for me. Could someone lend a hand in identifyin ...

Utilize Ajax to automatically populate a textbox with suggestions

I'm retrieving data via an AJAX call. How can I bind the data for auto-completion in a text box using both the name and ID as fields? What is the best way to bind this data in the frontend and retrieve the selected name's ID in the backend using ...

Can anyone provide instructions on how to create a theme change animation using Vuetify?

Follow these steps to understand what I'm describing: Go to the Vuetify website Click on the settings icon Choose between the dark or light theme option. When you switch between themes, there is an animation that occurs. A circle starts expanding fr ...

The SVG image does not display in browsers other than Internet Explorer (IE)

I am encountering an issue with adding a menu toggle image in SVG format to my HTML. Unfortunately, the image is not displaying as expected. Here are screenshots for comparison between Explorer and Chrome: https://i.stack.imgur.com/74sqh.png https://i. ...

Triggering document.ready() in a new window or tab using jQuery after opening the window

How can I properly initiate a document.ready() in the window (myWindow) where I'm injecting data using the code provided below? $.ajax({ type: 'POST', url: url, dataType: 'html', data: { plogid: parentLogid ...

Achieve dynamic styling and adjust window size using window.open

My mind is exhausted after days of trying: function prtDiv( o ) { var css = 'body {font:normal 10px Arial;}' ; var wo = window.open('','print','width=600,height=600,resizable=yes'); wo.document.write( '<he ...

Unable to select a checkbox in an ASP.NET Core MVC view

In the process of developing an ASP.NET Core 3.1 MVC application, I am faced with a task to implement a dynamic checkbox menu for selecting fruits and storing the choices in another data source. However, encountering an issue where I'm unable to sele ...

What could be causing the additional space in this div? Any suggestions on how to resolve it?

In a mock project, there seems to be extra space at the bottom of this element. https://i.sstatic.net/3s52c.jpg I've reviewed the code thoroughly but I'm unable to pinpoint where the mistake lies. Can someone assist in identifying the error? H ...

How can I ensure my md-sidenav takes up the entire height when using ui-router?

Currently, I am utilizing the most recent version of Angular Material (1.0.0) library and I am attempting to ensure that my <md-sidebar> panel occupies the entire height of the available space on the webpage. While it functions correctly on a regul ...

Tips for implementing border-radius on Internet Explorer 8:

Similar Question: How to create rounded borders in IE8 using CSS? I typically use css border-radius for the design of my webpages. While they display well in Firefox, I am facing compatibility issues with IE8. Can anyone offer any assistance? Thank yo ...

Populating Fullcalendar with data from a database using ASP.NET C#

I want to integrate Fullcalendar into my asp.net web forms app and connect it to a database for data binding. Can anyone provide guidance on how to achieve this? ...

Cannot add padding to the DIV element

Here is some HTML and CSS code that I've provided. .x{ border-bottom: 1px solid #000; } .y { border-bottom: 1px solid #000; } .z li{ display: inline; padding-top: 50px; } <div class="x"> <br> <br> <b ...

Required inputs do not disrupt the form's action flow

Here is the HTML code that I am working with: function document_save_changes(){ if (is_key_dirty == true){ var elm = document.getElementById('set_doc_button'); key_change_warning(elm, 'D'); return; } if (document_save_warning('A ...

Is the function failing to detect the updated variable because it is not declared as a global variable?

I have created a quiz with 7 select boxes and a submit button, aiming to display a warning error if the select boxes are not changed or show the score if they are changed. I initialized a variable called 'changed' as false. When a select box is ...