Creating a dynamic carousel with adjustable images

My image carousel is giving me trouble with responsiveness, specifically the height of the images. While the width looks okay, the height is only half of what I need. Can someone offer some ideas on how to make my image height 100% responsive? I've tried setting it to 500px, but I want it to adjust its height automatically.

Here is one of the images:

And here is another image for reference:

Below is the HTML code snippet:

<!DOCTYPE html>
<html>
    <head>
        <title>Student Portal</title>
        <link rel="stylesheet" href ="css/bootstrap.min.css">
        <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
        <link href="style.css" rel ="stylesheet">
        <link rel="shortcut icon" type="img/png" href="img/asd.png"/>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    ...
</html>

Next up, a sample from the CSS file:

.navbar-header{
  height: 74px;
}
...
.carousel-inner img{
   height: auto;
  width: 100%;
}
@media(min-width: 768px) and (max-width: 1024px){
   .img-responsive{
    width: 260px;
    height:70px;
  }
  ...
}

Answer №1

Here's a suggestion to test out

.item.active img {
  display: block;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
}

Answer №2

Experience the power of viewport-relative units with CSS3. Utilize 100vh for 100% of the viewport height and 100vw for 100% of the width, perfect for creating full screen slides.

Give this code a try:

.carousel-inner img{
   height: 100vh;
   width: 100%;
}

Please note that while this is supported by IE11, other browsers should have no issues with it.

UPDATE :

Add the following class to your style sheet:

.item{
    height: 500px;
}

.item img {
    width: 100%;
    height: 100%;
}

Check out our demo here: https://jsfiddle.net/qd4xhzvm/

Answer №3

After some experimentation, I managed to fix the issue by applying a max-height property to the .carousel-inner img selector. Appreciate the assistance though!

.carousel-inner img{
  width: 100%;
  max-height: 500px;
}
.carousel-inner{
  height: 500px;
}

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

What is the best way to display the panel during a postback?

I have a group with two radio buttons labeled purchase and expenses. When the purchase radio button is clicked, the panelpurchase will be displayed, and similarly, the panelexpense will show for the expenses radio button. Check out the image of the output ...

The button component is unresponsive

An app was developed with a component containing signin and signup buttons on the right side. However, there is an issue where the Sign up button is not clickable. Below is the code snippet for the component => import React from "react"; expo ...

The iPage server has encountered a 403 Forbidden Error, preventing

My website is linked with WordPress, but I'm encountering a 403 forbidden error in the sub-menu. Can someone assist me with this issue? I have uploaded a screenshot of the folder in iPage here Additionally, I want my WordPress page to show up correc ...

Capturing the final image within a WordPress article - an unspecified quantity

My goal is to identify the final image in a Wordpress post content and place a title over it. Each post may contain a different number of images, which is why I need to target the last one specifically. I currently have code that successfully targets the ...

Are background images covering hidden text detrimental to accessibility?

Is there a way to display images of text instead of actual text for my menu? I have implemented spans within each menu link. These spans have specific dimensions, block display properties, the text is indented to be hidden, and the background image is set ...

Creating a new form upon clicking

By clicking the "Add New Job" link, a new form with three fields will appear. This is the primary form: <h2>JOB EXPERIENCE 1</h2> <div class="job-content"> <input type="text" value="Company" name="company" /> <input type="te ...

Is there a way to perfectly center this image with the rest of my text content?

Seeking assistance in aligning this image to the right alongside other text content. Currently, when the code is executed, the image is pushed down and positioned below the text on the right side. Ideally, I would like the image to be aligned evenly with ...

Encountering issues with integrating Sass into Angular 4

Hi there! I recently started a new project in Angular 4 and encountered some issues with the Sass styling. Every time I try to add sass and run the project, I keep getting this error message: body{ h1{ color : red; } } ^ Invalid ...

Troubleshooting issue with parsing MySQL data in HTML table using Node.js

Seeking Assistance! I am currently in the process of developing a node file that displays data from MySQL on an HTML page with a search bar. My issue is that sometimes when I run the code, enter something into the search bar and hit the button, it works s ...

Accessing the phone number input from a form in Rails and verifying its presence in the database. Implementing distinct ajax responses based on the existence of the value

Looking for a way to verify phone numbers? The process involves users entering a phone number, submitting the form, and cross-referencing it with a database of phone number records to determine if it's valid. My goal is to provide different AJAX respo ...

The function Event.preventDefault seems ineffective when attempting to block input of CJK (Korean) characters in a v-text-field of type

Currently, I am tackling an issue in a Vue project where I need to fix a small bug. However, the solution seems quite challenging. I have managed to make the v-text-field accept only numerical input, which is functioning well. <v-text-field type=" ...

BASH-SHELL SCRIPT: Display a specific portion of content from a file

Recently, I stumbled upon a text file containing a snippet of HTML code: >>nano wynik.txt which includes the following text: 1743: < a href="/currencies/lisk/#markets" class="price" data-usd="24.6933" data-btc= "0.00146882" My goal is to extr ...

Show whether the day is even or odd with the JavaScript getDay object

I'm currently working on a task where I need to show the text "Even Day" if the day of the month is 2, 4, 6..., and "Odd Day" for days such as 1, 3, 5, and so on. I attempted to achieve this by setting up an array linked to the getDay object, but unfo ...

Is there a way to load the right amount of images in advance, depending on the size of the

I'm currently trying to optimize the loading of Largest Contentful Paint (LCP) candidate images based on device size, but I'm encountering difficulties. The issue at hand: On smaller screens, only one image is displayed in a carousel On larger ...

Header that sticks to the top of a container as you scroll through it

Many questions arise regarding sticky elements in the DOM and the various libraries available to handle them, such as jquery.pin, sticky-kit, and more. However, the issue with most of these libraries is that they only function when the entire body is scro ...

Navigating Websites in Google Search

Whenever I search for keywords related to my website on Google, the search results show my website's content and address. However, when I click on the link, it redirects me to a different unrelated website. Click here to view an image ...

Obtain the height and width of the original images from the href and assign them to your attributes using jQuery

Hey there pals, I'm currently on a mission to fetch the dimensions (height and width) of an image from a hyperlink and then insert those values into its attribute. This task has got me going bonkers! Here's my snippet: <figure> <a ...

Accessing Ionic rootScope within the config stateprovider - A step-by-step guide

Is it possible to access the value of $rootScope in the following line? .config(function($stateProvider, $urlRouterProvider) { $stateProvider // I am trying to retrieve the value of $rootScope here. } ...

Navigating to User's Specific Info Page using Node.js

Would love some input on my current issue. I have a table featuring a list of users, and my goal is to display user information in detail whenever a user (which corresponds to a row in the table) is clicked. The process involves identifying which user was ...

Is there a way to shift a background image pattern?

After searching extensively, I came up empty-handed and am seeking guidance on how to achieve a specific effect. Specifically, I am in need of a JavaScript or jQuery script that can smoothly shift a background image to the right within a designated div con ...