How do I get the width of a picture

F

find clausen

Is it possible to get the width of a picture:

<img src="../graphics/press/bw21.jpg" width=400 height=555 alt=""
border="0">

the make a box be exactly the width of the picture:

document.write('<div class="box" style="width:'+ w +'px">');
 
A

ASM

find clausen a écrit :
Is it possible to get the width of a picture:

<img src="../graphics/press/bw21.jpg" width=400 height=555 alt=""
border="0">

the make a box be exactly the width of the picture:

document.write('<div class="box" style="width:'+ w +'px">');

Why to use a div to do a box for a picture ?
CSS can't they do that for you ?

img.box {
padding: 15px;
border: 8px outside goldenrod;
background: white;
}

<img class="box" ... />


Anyway, with a div :
====================

..box {
position: absolute;
border: goldenrod outset 8px;
padding: 2px;
background: #ffc;
}
..box img { border: gold inset 5px; padding: 12px; background: white; }

<div class="box">
<img src="01.jpg" alt="" />
</div>


And with JS :
=============

<div style="position:relative;border:5px solid maroon;background:white">
<img src="01.gif" style="margin:8px;"
onload="parentNode.style.width=(this.width*1+16)+'px';
parentNode.style.height=(this.height*1+16)+'px';"
alt="" title="bodered image" />
</div>
 
D

dd

Is it possible to get the width of a picture:

<img src="../graphics/press/bw21.jpg" width=400 height=555 alt=""
border="0">

the make a box be exactly the width of the picture:

document.write('<div class="box" style="width:'+ w +'px">');

It seems like you're making it hard for yourself
by trying to find a value w to put in that width.
By just eliminating it, the box will expand to
the size of the image anyway. Similarly, unless
you're specifically resizing the image to 400 by
555, dropping the sizes from the image tag will
also let the image be the size it actually is.

<img src="../graphics/press/bw21.jpg" alt=""
border="0">
.....
document.write('<div class="box">');
 
F

find clausen

It seems like you're making it hard for yourself

The box is for the text beneath the picture:

<a class="no" href="press-012.html">
<img src="../graphics/press/004.jpg" width=400 height=480 border=0
alt=""></a>

<div class="box z06">
xaaa dad aadad
</div>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top