Shrink the size of the rotating banner to its smallest width possible

I have implemented a rotating banner on my website by using the code from unslider.com. The banner consists of four images, each 2080px wide, which is the maximum size I want for my site. I aim to scale both the website and the images down to a minimum width of 1024px. While the website successfully resizes accordingly (stops at 1024px), the images do not adjust.

Therefore, I am seeking help to find a solution that will allow the banner and its images to resize proportionally to a minimum of 1024px. To facilitate this process, I have set up a CodePen demo here:

http://codepen.io/trevoray/pen/LENvwx/

Here is the HTML code block corresponding to the implementation:

 <!DOCTYPE html>
 <html>

 <head>

<meta charset="UTF-8">

<title>CodePen - Rotating Image Banner that resizes down to minimum size</title>

<style type="text/css">
#container {
max-width:1280px;  
min-width:1024px;
  }


.banner { 
 position: relative;
 overflow: auto; 
 width:1280px;


}

 .banner ul {margin: 0; padding: 0;  }

 .banner li { 
 list-style: none; 
 }

.banner ul li { 
float: left; 
display:block;
max-width:100%;
height:295px;
    -moz-background-size: 100% 100%;
    -o-background-size: 100% 100%;
    -ms-background-size: 100% 100%;
 }

#image1 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image1.png");
}

#image2 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image2.png");
}

#image3 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image3.png");
}


 #image4 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image4.png");
}

</style>
</head>

 <body>

 <div id="container">

<div class="banner">
<ul>
    <li id="image1"></li>
    <li id="image2"></li>
    <li id="image3"></li>
    <li id="image4"></li>
 </ul>
 </div>

{Lorem Ipsum text remains unchanged for brevity}

 </div>

<script src='http://codepen.io/assets/libs/fullpage/jquery.js'></script>
<script src='http://unslider.com/unslider.min.js'></script>

<script>
$(function() {
$('.banner').unslider();
});


</script>

</body>

 </html>

Answer №1

To ensure that the width of .banner adjusts to the parent div or window width, set it to auto.

In CodePen, this will not work; you must test it in an HTML document.

<!DOCTYPE html>
 <html>

 <head>

<meta charset="UTF-8">

<title>CodePen - Rotating Image Banner Resizing to Minimum Size</title>

<style type="text/css">
#container {
max-width:1280px;  
min-width:1024px;
  }


.banner { 
 position: relative;
 overflow: auto; 
 width: auto;


}

 .banner ul {margin: 0; padding: 0;  }


 .banner li { 
 list-style: none; 
 }

.banner ul li { 
float: left; 
display:block;
max-width:100%;
height:295px;


 /*     -webkit-background-size: 100% 100%;*/
    -moz-background-size: 100% 100%;
    -o-background-size: 100% 100%;
    -ms-background-size: 100% 100%;
 /*     background-size: 100% 100%;*/

 }

#image1 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image1.png");
}

#image2 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image2.png");
}

#image3 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image3.png");
}


 #image4 {

background-image:url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/189477/image4.png");
}

</style>
</head>

 <body>

 <div id="container">

<div class="banner">
<ul>
    <li id="image1"></li>
    <li id="image2"></li>
    <li id="image3"></li>
    <li id="image4"></li>
 </ul>
 </div>

 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus eu arcu feugiat, posuere felis    vitae, malesuada nulla. Integer dapibus lacus purus. Fusce hendrerit vestibulum purus sed bibendum. Vestibulum turpis tellus, cursus in ullamcorper eget, viverra a dolor. Maecenas sed erat quis nibh iaculis rhoncus in eu mi. Vestibulum sit amet nulla molestie, venenatis magna vel, porta ligula. Phasellus dictum rhoncus diam id ullamcorper. Ut scelerisque purus ac neque semper, non eleifend arcu egestas. Curabitur lacinia est laoreet ligula volutpat, ut suscipit augue interdum. Nulla rutrum mi vel blandit suscipit. Donec ac elit et velit mattis fringilla. Mauris ac cursus massa. Integer vehicula non eros eu dapibus. Aliquam volutpat rhoncus fringilla. Nullam finibus euismod lectus quis tempus.<BR><BR>

  Quisque facilisis eros sit amet nisi malesuada, eget blandit ex convallis. Donec tellus est, placerat nec sapien id, ornare consequat nulla. Curabitur eleifend risus nec ante commodo pharetra id ut lectus. Proin ac tristique lectus. Proin ac quam a dolor auctor rhoncus. Aenean lobortis faucibus erat at sodales. Praesent non lacus quis magna mattis viverra. Integer consequat nibh diam, sed euismod elit tincidunt eget. Donec eu nunc vitae ante ultrices pellentesque sit amet quis eros. Praesent at placerat massa. Vestibulum malesuada vulputate augue a dapibus. Vestibulum sit amet leo quis justo tincidunt tempor.

 </div>

<script src='http://codepen.io/assets/libs/fullpage/jquery.js'></script>
<script src='http://unslider.com/unslider.min.js'></script>

<script>
$(function() {
$('.banner').unslider();
});


</script>

</body>

 </html>

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

Issue with uploading files on remote server using PHP

Below is the code I am currently using: <form action="index.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" id="file"><br><br> <input type="submit" value="submit" name="submit"> </form> ...

Adding data to a pre-made JavaScript file template to create a fresh document

In my web application, I have a form with multiple inputs: <form action=""> Title1:<br> <input type="text" name="title1"> <input type="text" name="title1Description"> <br> Title2:<br> <input t ...

Having difficulty with loading images lazily in a jQuery Mobile app with LazyLoadXT feature

Struggling to incorporate lazy loading in my jQM app with Lazy Load XT v1.0.6. Oddly, images only appear when switching browser tabs, not while scrolling down. This happens on Firefox and Chrome. <img src="/img/default-img.jpg" data-src="/img/product/ ...

What new features have they incorporated into the latest Foxy Bingo website?

Foxy Bingo has recently unveiled a new website at www.foxybingo.com that operates as a single-page site, allowing users to click on main menu items to navigate through the content by scrolling down the page. Interestingly, when a link is clicked, the URL ...

I am currently seeking a way to validate if a variable corresponds to the choice made in the dropdown menu. Any suggestions on how to accomplish this task?

I have put together a simple drop down menu. My goal is to grab the currently selected value from the drop down list, store it in a variable, and display it in the console. The ultimate objective is to compare that variable with another one to determine if ...

Introducing Enhanced Google ReCaptcha Verification and Pre-Submission Evaluation

I'm new to PHP, jQuery, and AJAX. I'm attempting to integrate the new Google Recapcha. It appears as follows - After Click- And After verified- The code in index.php is as follows- <html> <head> <title>Google reCAPTCHA ...

Updating Ajax and selecting input fields in a form

I am currently using ajax code with jQuery and the x-editable plugin to update a select field. <a href="#" id="days" data-pk="<?php echo $id; ?>" data-url="post.php" data-title="days" data-type="select" class="editable editable-click" ...

Sending data to a JSON file with jQuery and AJAX: Step-by-step guide

While there are numerous tutorials available on how to retrieve data from json files using jQuery and ajax, I have been unable to find any that demonstrate how to POST data to a json file. If anyone has a script or example they could share with me on how t ...

Is it advisable to break down views into smaller components in Vuejs?

I'm currently managing a project with two folders for components - 1) src/components/ and 2) src/views. The general components like a drawer or nav are stored in the first folder, while the pages (views) are stored in the second. Now I face a challen ...

Angular 2 Component attribute masking

In my Angular 2 component called Foobar, I have defined a property named foobar: import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-foobar', templateUrl: './foobar.component ...

Angular 4 application fails to occupy the entire screen height

Here is how my app.component looks: <div class="wrapper"> <app-header></app-header> <router-outlet></router-outlet> <footer> <section class="page group"> {{ 'COMPANY.address' | translate ...

What are the steps to create a custom progress bar using JavaScript?

I have experience with HTML and CSS. Below is the HTML code: <div id="wrapper"> <ul id="top"> <center><li><a href="#one" class="button">GENERATE</a></li></center> </ul> <div class="box" i ...

What is the best way to send an array of objects to a Jade template?

I'm looking to retrieve an array of objects from MongoDB and pass it to the client... Here is an example object: var objeto_img= { name:'name of the file', ...

Utilizing Nested Ajax Calls: Traversing through IDs in subsequent ajax requests

Currently, I am utilizing the Instagram API to retrieve comments by extracting the post's id and inputting it into the URL of the comments API. However, there seems to be an issue with looping through the ids on the second AJAX call as it keeps repeat ...

Experiencing low frame rates in animations using requestAnimationFrame or setTimeout

I have been experimenting with different ways to achieve smooth animation at a constant frame rate, but I haven't had much success. Currently, I am using three.js and webgl for rendering the scene, and I have tried implementing the animation loop usin ...

automatically adjusting the font size

There are 3 paragraphs of text on a page...I am looking to dynamically change the font size of these paragraphs every 3 seconds....is that feasible? Specifically, I want paragraph 1 to be initially displayed at 10px and paragraph 2 at 8px. Then, aft ...

The <a href="#divtagid"> link is incapable of triggering the opening of the div tag when called from JavaScript

I need help with displaying the content of a div with the id "hello" in maindiv when clicking on the href "Click Here", but it's not working as expected. Here is the code I have: $(document).ready(function() { var newhtml = '<a href="#he ...

In AngularJS, when a user clicks on a specific element, the program should fetch the corresponding value from a separate dataset and display it

Hello, I am just starting out with angularjs and here is my current js file setup: angular.module("mainModule", []) .controller("mainController", function ($scope) { $scope.ProdMenu = [ {ProductMenuName: "CBS" ...

Submenu fails to remain expanded

Having a minor issue with my dropdown menu. Whenever I hover over a link, the submenu pops out briefly but doesn't remain open. The issue seems to be related to the "content" div element, as removing it makes the menu functional. However, I can&apo ...

Identifying when an element is in or out of view using Next.js and TypeScript

I'm currently working on an app using Next and Typescript. The app features a navigation bar at the top of the screen, and I need it to change its style once it reaches a certain point in the view. I attempted to use jQuery for this purpose, but encou ...