473,464 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Resize images placed inside DIV based on screen/browser size width

I have a "Looped Slider" that displays a series of images, but I've had to manually resize the images (using height/width tags), but I'm looking for some code that will take the width of the DIV, and resize/adjust the height/width of the images automatically.

Here is the code for the looped slider:

Expand|Select|Wrap|Line Numbers
  1.         <div id="loopedSlider" class="feature">
  2.  
  3.             <div class="container">
  4.  
  5.                 <div class="slides">
  6.  
  7.                     <div><img onclick="window.location='page1.html';" src="./images/image1.jpg" width="600" height="350" alt="Image 1" border="0" />
  8.                     </div>
  9.  
  10.                     <div><img onclick="window.location='page2.html';" src="./images/image2.jpg" width="600" height="350" alt="Image 2" border="0" /></div>
  11.  
  12.                     <div><img onclick="window.location='page3.html';" src="./images/image3.jpg" width="600" height="350" alt="Image 3" border="0" /></div>
  13.  
  14.                     <div><img onclick="window.location='page4.html';" src="./images/image4.jpg" width="600" height="350" alt="Image 4" border="0" /></div>
  15.  
  16.                     <div><img onclick="window.location='page5.html';" src="./images/image5.jpg" width="600" height="350" alt="Image 5" border="0" /></div>
  17.  
  18.                     <div><img onclick="window.location='page6.html';" src="./images/image6.jpg" width="600" height="350" alt="Image 6" border="0" /></div>
  19.  
  20.                     <div><img onclick="window.location='page7.html';" src="./images/image7.jpg" width="600" height="350" alt="Image 7" border="0" /></div>
  21.  
  22.                 </div>
  23.  
  24.             </div>
  25.  
  26.           </div>
  27.  
Here is the CSS page information:

Expand|Select|Wrap|Line Numbers
  1. #loopedSlider {
  2.     POSITION: relative
  3. }
  4. #loopedSlider .container {
  5.     POSITION: relative; LEFT: 50px; WIDTH: 600px; HEIGHT: 350px; OVERFLOW: hidden
  6. }
  7. #loopedSlider .slides {
  8.     POSITION: absolute; TOP: 0px; LEFT: 0px
  9. }
  10.  
I would like the width and height of the images to adjust automatically in the main HTML page, and would also like the "loopedSlider .container" width and height to adjust automatically in the CSS page (based on the web browser's width).

So if a web browser window was resized, it would resize the "loopedSlider .container", and also resize the width and height of the images (in the div class "slides")

I would like the image width and height to be adjusted based on the width of the browser window.

I would like the image width to be 70% of the browser window width.

I would like a 0.58 aspect ratio in the width/height of the image. So if a browser window was 800 wide, it would then make the LoopedSlider image width="600" (75% of browser width) and the image height would be height="348" (58% of image width)


If the width of the browser window is 800, then I would like to make the image width="600" and height="350"

I would like the image width to be 75% of the browser width, and would like the image height to be 58% (.58 aspect ratio) of the image width.

If the browser window is 1000 wide, then I would like to the images to be width="750" and height="435".

I'm looking for some code that will detect the current browser width and resize the "width" and "height" variables accordingly.

Expand|Select|Wrap|Line Numbers
  1.         <div id="loopedSlider" class="feature">
  2.  
  3.             <div class="container">
  4.  
  5.                 <div class="slides">
  6.  
  7.                     <div><img onclick="window.location='page1.html';" src="./images/image1.jpg" width="600" height="350" alt="Image 1" border="0" />
  8.                     </div>
  9.  
  10.                     <div><img onclick="window.location='page2.html';" src="./images/image2.jpg" width="600" height="350" alt="Image 2" border="0" /></div>
  11.  
  12.                     <div><img onclick="window.location='page3.html';" src="./images/image3.jpg" width="600" height="350" alt="Image 3" border="0" /></div>
  13.  
  14.                     <div><img onclick="window.location='page4.html';" src="./images/image4.jpg" width="600" height="350" alt="Image 4" border="0" /></div>
  15.  
  16.                     <div><img onclick="window.location='page5.html';" src="./images/image5.jpg" width="600" height="350" alt="Image 5" border="0" /></div>
  17.  
  18.                     <div><img onclick="window.location='page6.html';" src="./images/image6.jpg" width="600" height="350" alt="Image 6" border="0" /></div>
  19.  
  20.                     <div><img onclick="window.location='page7.html';" src="./images/image7.jpg" width="600" height="350" alt="Image 7" border="0" /></div>
  21.  
  22.                 </div>
  23.  
  24.             </div>
  25.  
  26.           </div>
  27.  
and also resize the CSS "loopedSlider .container" width and height automatically so that the loopedSlider images (slides) will fit. (Make the "loopedSlider .container" width a percentage of the browser width (i.e. 75% of browser width).

Expand|Select|Wrap|Line Numbers
  1. #loopedSlider {
  2.     POSITION: relative
  3. }
  4. #loopedSlider .container {
  5.     POSITION: relative; LEFT: 50px; WIDTH: 600px; HEIGHT: 350px; OVERFLOW: hidden
  6. }
  7. #loopedSlider .slides {
  8.     POSITION: absolute; TOP: 0px; LEFT: 0px
  9. }
  10.  
Could someone please help by posting a corrected HTML/CSS code snippet, as to how I could do this?
Nov 23 '10 #1
1 7249
drhowarddrfine
7,435 Expert 4TB
Just set the height/width using percentages.
Nov 23 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nick D. | last post by:
Hi All! I hope there's someone that might be able to help me with this...I'm a designer, not a developer, so i hope this isn't TOO basic. Basically, I have a topbar that's a simple JPG image that...
4
by: Bob Richardson | last post by:
Is it possible for an image to SHRINK (both height and width, keeping same h/w ratio) when the browser's width is reduced? It's easy to have both h & w increase, as needed, to fill up 100% of the...
4
by: Matthew Louden | last post by:
It happend to me more than once. When I create web controls or move the positions in VS.NET, I encountered the following run-time errors: It doesn't matter what controls I create, the following...
2
by: John | last post by:
Hi I have dragged a few controls over to a web form. The html code generated is as follows; <asp:TextBox id="StaffCode" runat="server"></asp:TextBox>&nbsp; <asp:Button id="Submit"...
0
by: davidr | last post by:
Hi, I have a panel that I load user Control in no problem. The problem arrises when I do a post back on one of these user controls. I have button it does a click event. In this click event I...
11
by: eholz1 | last post by:
Hello PHP group, I am using some php code to check the size of images, and then resize or determine new dimension for the image. GD seems quite slow. It takes about 5 seconds (plus or minus) to...
2
by: ezhils | last post by:
How to resize the form controls based on the screen resolution?
0
by: ramuksasi | last post by:
Hi, I've an asp.net .ascx form and a gridview on that form.I've placed that form on an .aspx. Now while I'm trying to import data from gridview to excel it is showing the error "Control 'GridView'...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.