473,609 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

image grows outside a box

Abs
Hi!

I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
therefore the image grows outside the box if it's bigger than the box.
Is there a way to force the image to resize itself automatically to fit
the box with CSS ?
Thanks in advance
Jul 21 '05 #1
8 9437
On Fri, 26 Nov 2004 18:05:16 +0100, Abs <ab**@yahoo.com > wrote:
Hi!

I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
therefore the image grows outside the box if it's bigger than the box.
Is there a way to force the image to resize itself automatically to fit
the box with CSS ?


Best solution is to actually resize the image with server-side script.
Scaling images in the browser does not usually work out very well.
Jul 21 '05 #2
in comp.infosystem s.www.authoring.stylesheets, Abs wrote:
Hi!

I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
Well, you do know. Unless you are getting it from another site?
therefore the image grows outside the box if it's bigger than the box.
Why did you set div boxes dimensions then?
Is there a way to force the image to resize itself automatically to fit
the box with CSS ?


No. What is your real problem? URL?

--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Jul 21 '05 #3
In message <30************ *@uni-berlin.de>, Abs <ab**@yahoo.com > writes
Hi!

I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
therefore the image grows outside the box if it's bigger than the box.
Is there a way to force the image to resize itself automatically to fit
the box with CSS ?
Thanks in advance


If you have set the size (width, height) of the containing div, then set
the width of the image to 100%. The image will then be resized by the
browser to fill the container.

However, the results of image resizing only looks acceptable if the
image is resized downwards. i.e. not presented in a container bigger
than the physical size of the image.

regards.

--
Jake

Jul 21 '05 #4
"Abs" wrote in comp.infosystem s.www.authoring.stylesheets:
I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
therefore the image grows outside the box if it's bigger than the box.
Is there a way to force the image to resize itself automatically to fit
the box with CSS ?


Why not resize the box to fit the image? Why make people download a
big image only to see a small one?

--
Stan Brown, Oak Road Systems, Tompkins County, New York, USA
http://OakRoadSystems.com/
HTML 4.01 spec: http://www.w3.org/TR/html401/
validator: http://validator.w3.org/
CSS 2.1 spec: http://www.w3.org/TR/CSS21/
validator: http://jigsaw.w3.org/css-validator/
Jul 21 '05 #5
Abs
Stan Brown wrote:
"Abs" wrote in comp.infosystem s.www.authoring.stylesheets:

I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
therefore the image grows outside the box if it's bigger than the box.
Is there a way to force the image to resize itself automatically to fit
the box with CSS ?

Why not resize the box to fit the image? Why make people download a
big image only to see a small one?


Because I need the page (and the images) to be proportional to the
screen resolution, that's why use percent units to set the box
dimensions and position. Anyways, it seems it cannot be done, but I
still don't understand this css behaviour, not resizing the content to
fit the dimensions of its enclosing box.
Jul 21 '05 #6
Abs wrote:
Stan Brown wrote:
"Abs" wrote in comp.infosystem s.www.authoring.stylesheets:

I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
therefore the image grows outside the box if it's bigger than the
box. Is there a way to force the image to resize itself automatically
to fit the box with CSS ?


Why not resize the box to fit the image? Why make people download a
big image only to see a small one?

Because I need the page (and the images) to be proportional to the
screen resolution, that's why use percent units to set the box
dimensions and position. Anyways, it seems it cannot be done, but I
still don't understand this css behaviour, not resizing the content to
fit the dimensions of its enclosing box.


How about this approach? In the image onload event, the image is resized
to fit into the div (hardcoded to 300px square for this example) using
javascript. The image is made as large as possible while preserving it's
width to height ratio. Requires javascript being enabled, else image
stays its original size.

<script type="text/javascript">
function resizeimage(img name){
var d1=document.ima ges[imgname];
//get current image size and w/h ratio
var currentw=d1.wid th;
var currenth=d1.hei ght;
var currentwhratio= (currentw/currenth);
//alert('w '+currentw+' h '+currenth+' w/h '+currentwhrati o);
//make image as large as possible while still
//fitting inside div and maintaining it's w/h ratio
if(currentw>cur renth){
d1.width=300;
d1.height=300/currentwhratio;
} else {
d1.height=300;
d1.width=300*cu rrentwhratio;
}
//alert('h '+d1.height+' w '+d1.width);
}
</script>

<style type="text/css">
..imagediv{
background-color: #000000;
width: 300px;
height: 300px;
text-align: center;
}
..img{
border: 0px;
}
</style>

<div class='imagediv ' >
<img onload="resizei mage('image1'); "
src="C:\Archive \graphic\Bicycl ingInSantaCruz. jpg"
name="image1">
<div>
Jul 21 '05 #7
Abs
jake wrote:
In message <30************ *@uni-berlin.de>, Abs <ab**@yahoo.com > writes
Hi!

I have an image inside a DIV box with its dimensions specified. The
problem is that I don't know the dimensions of the image beforehand,
therefore the image grows outside the box if it's bigger than the box.
Is there a way to force the image to resize itself automatically to
fit the box with CSS ?
Thanks in advance

If you have set the size (width, height) of the containing div, then set
the width of the image to 100%. The image will then be resized by the
browser to fill the container.

However, the results of image resizing only looks acceptable if the
image is resized downwards. i.e. not presented in a container bigger
than the physical size of the image.

regards.


Ok, thank you very much, this made the trick!
Jul 21 '05 #8
in comp.infosystem s.www.authoring.stylesheets, Abs wrote:
Why not resize the box to fit the image? Why make people download a
big image only to see a small one?

Because I need the page (and the images) to be proportional to the
screen resolution,


Impossible. You mean wwindow size.
that's why use percent units to set the box
dimensions and position.


Not good idea. You end up getting text one word at line wery easily. At
least if you use any percentage smaller than 30%


--
Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2714
by: OneSolution | last post by:
Hi All, Here's what I'm trying to do. I have a diverse customer base, and as it grows, it's increasingly harder to figure out what aspect of our web site is selling and what is not. So I've been trying to use PHP (and/or ASP) to do some research on my customers. So I nosed around some web sites and found the following piece of code. <IMG
2
2286
by: tjv | last post by:
Hi all, I am working with images in python using PIL. I come from a MATLAB background so I am finding it to be sometimes frustrating to do things correctly and quickly. All I need to do is load an image and store a list of pixel coordinates at which the alpha channel is set to 1. In Matlab this would be easy...Lets say we have a 2x2x4 array that represents the image. I would just type something like: indices = find(im(:,:,3)==1);
6
16060
by: Haines Brown | last post by:
I find that when I use list-style-image with galeon or mozilla, padding is inserted between the symbol image and the following list text, while under IE 5.0 it seems to be inserted before the image instead of after it. li.up { list-style-image: url(../bin/arrow.png); height: 1.4em; margin-left: -0.4em; }
1
1914
by: Joan | last post by:
Hi! Im working with C++ & win API32. My Problem: I have in a matrix of unsigned chars the colours (in RGB format) of an image. The dimensions of the image are 720 x 576 (cols x rows). So the size of the matrix is 720*576*3 bytes (unsigned chars).
16
2437
by: Harry Putnam | last post by:
I keep stumbling around with varius alignment tags, even using STYLE tag with absolute positioning but not getting a simple job done. I have an arrangment like this: ____________________________________________ | | | Large headline that is really an image | | of Elaborate text created in photoshop. | | This is presente in terms of % of page so |
2
2623
by: UJ | last post by:
I have need to convert a text string (with formatting) to an image. This is so that I can resize the image to different sizes and the formatting stays exactly the same regardless of the size. I actually want the font size to increase/decrease as the image grows/shrinks much the way text does in a flash object. Is there an easy way to do this programmatically? It needs to be done behind the scenes on my web site - user enters some text - I...
35
2655
by: Stan Sainte-Rose | last post by:
Hi, What is the better way to save image into a database ? Just save the path into a field or save the image itself ? I have 20 000 images (~ 10/12 Ko per image ) to save. Stan
8
5594
by: jbrewer | last post by:
I'm trying to read in a FITs image file for my research, and I decided that writing a file decoder for the Python imaging library would be the easiest way to accomplish this for my needs. FITs is a raw data format used in astronomy. Anyway, I followed the example in the PIL documentation online, and I also had a look at the FITs image stub file included with PIL 1.1.5. I cooked up something that should work (or nearly work), but I keep...
20
9192
by: deepak | last post by:
Hi All, In C I heard the stack grows from top to bottom and heap from bottom to top. Is it compiler depend?
0
8083
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8573
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8224
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8406
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7013
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6062
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4026
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2535
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 we have to send another system
1
1676
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.