Connecting Tech Pros Worldwide Help | Site Map

Another CSS & Javascript Problem

Ang Talunin
Guest
 
Posts: n/a
#1: Jul 20 '05
Hey,
When I use the code beneath I'm trying to resize a img depending on the
resolution of the visitor.
The images resizes fine, but the table doesn't! That keeps using the widht
of the original image.
I tried to put td { width=60%} in the style tag, but that didn't help
either.
How to fix this???

thnx,

A.T.


<html>
<head>
<script language="JavaScript"><!--
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;
if (window.screen.width == "1024") {
document.write("<style>img { width=100%}</style>");
}
else if (window.screen.width == "800") {
document.write("<style>img { width=60%;}</style>");
}
// --></script>
</head>
<body>
<table><tr>
<td><img src='im1.jpg' ></a></td>
<td><img src='im2.jpg' ></a><td>
</tr>
</table>



Evertjan.
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Another CSS & Javascript Problem


Ang Talunin wrote on 10 okt 2003 in comp.lang.javascript:
[color=blue]
> Hey,
> When I use the code beneath I'm trying to resize a img depending on
> the resolution of the visitor.
> The images resizes fine, but the table doesn't! That keeps using the
> widht of the original image.
> I tried to put td { width=60%} in the style tag, but that didn't help
> either.
> How to fix this???
>
> thnx,
>
> A.T.
>
>
> <html>
> <head>
> <script language="JavaScript"><!--
> browser_version= parseInt(navigator.appVersion);
> browser_type = navigator.appName;
> if (window.screen.width == "1024") {
> document.write("<style>img { width=100%}</style>");
>}
> else if (window.screen.width == "800") {
> document.write("<style>img { width=60%;}</style>");
>}
> // --></script>
> </head>
> <body>
> <table><tr>
> <td><img src='im1.jpg' ></a></td>
> <td><img src='im2.jpg' ></a><td>
> </tr>
> </table>[/color]

1
width=60%;
should be
width:60%;

2
this is NOT 60% of the original img width, but 60% of the td width !

3
The </a>'s make no sense here.

4
The last <td> should be </td>

=========================

This will do what you probably want:

<style>
table {width:100%;} /* follows the window width */
td {width:50%;} /* follows the table width */
img {width:100%;} /* follows the td width */
</style>

<table><tr>
<td><img src='im1.jpg'></td>
<td><img src='im2.jpg'></td>
</tr></table>

not tested.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Ang Talunin
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Another CSS & Javascript Problem


> <html>[color=blue][color=green]
> > <head>
> > <script language="JavaScript"><!--
> > browser_version= parseInt(navigator.appVersion);
> > browser_type = navigator.appName;
> > if (window.screen.width == "1024") {
> > document.write("<style>img { width=100%}</style>");
> >}
> > else if (window.screen.width == "800") {
> > document.write("<style>img { width=60%;}</style>");
> >}
> > // --></script>
> > </head>
> > <body>
> > <table><tr>
> > <td><img src='im1.jpg' ></a></td>
> > <td><img src='im2.jpg' ></a><td>
> > </tr>
> > </table>[/color]
>
> 1
> width=60%;
> should be
> width:60%;[/color]

I tried to change the first if in::

if (window.screen.width == "1024") {
document.write("<style>table{ width:100%} td{ width:50%} img{
width:100%}</style>");
}

But that doesn't work....

any other ideas?


David Dorward
Guest
 
Posts: n/a
#4: Jul 20 '05

re: Another CSS & Javascript Problem


Ang Talunin wrote:
[color=blue]
> if (window.screen.width == "1024") {
> else if (window.screen.width == "800") {
> }[/color]

What about people with other resolutions?

What about people who don't maximise their browser window?

--
David Dorward http://dorward.me.uk/
Evertjan.
Guest
 
Posts: n/a
#5: Jul 20 '05

re: Another CSS & Javascript Problem


Ang Talunin wrote on 10 okt 2003 in comp.lang.javascript:
[color=blue]
> I tried to change the first if in::
>
> if (window.screen.width == "1024") {
> document.write("<style>table{ width:100%} td{ width:50%} img{
> width:100%}</style>");
>}
>[/color]

the "" around 1024 are unneccessary

This cannot work, because the screen with is only available when the page
is being build, and the document.write() destroys the build.

I showed you earlier, what I think is the best, only using css, but since
perhaps I do not understand what you want, that is just my assumption.

Remember %-width is percent of the container, not of the img itself.

What always should be possible is two pages with clientside relocation:

// this is in "mypageLOW.html"
if (window.screen.width > 1023 ) location.href="mypageHIGH.html"

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Ang Talunin
Guest
 
Posts: n/a
#6: Jul 20 '05

re: Another CSS & Javascript Problem



"David Dorward" <dorward@yahoo.com> schreef in bericht
news:bm7amd$lad$1$8302bc10@news.demon.co.uk...[color=blue]
> Ang Talunin wrote:
>[color=green]
> > if (window.screen.width == "1024") {
> > else if (window.screen.width == "800") {
> > }[/color]
>
> What about people with other resolutions?[/color]

They are taking care of also, but that's not the problem....
[color=blue]
> What about people who don't maximise their browser window?[/color]

I don't care. If they want to see the foto's I'm displaying correctly,
without scrollbars the just have to maximise...


Ang Talunin
Guest
 
Posts: n/a
#7: Jul 20 '05

re: Another CSS & Javascript Problem


> the "" around 1024 are unneccessary

ok[color=blue]
>
> This cannot work, because the screen with is only available when the page
> is being build, and the document.write() destroys the build.
>
> I showed you earlier, what I think is the best, only using css, but since
> perhaps I do not understand what you want, that is just my assumption.[/color]

But why is the <style> in the document.write changing the size of the
images, but not the size of the cells of the table?



Evertjan.
Guest
 
Posts: n/a
#8: Jul 20 '05

re: Another CSS & Javascript Problem


Ang Talunin wrote on 11 okt 2003 in comp.lang.javascript:[color=blue]
> But why is the <style> in the document.write changing the size of the
> images, but not the size of the cells of the table?[/color]

because you specified 60%, this means that the image wil fill 60% of the
container, and that is the TD:

<style>
IMG {width:60%;}
</style>

If you want to change the size of the td, and fill the td with the img,
you have to specify:

<style>
TABLE {width:70%;}
TD {width:50%;}
IMG {width:100%;}
</style>

<table>
<tr>
<td><img src="..."></td>
<td><img src="..."></td>
</tr>
<tr>
<td><img src="..."></td>
<td><img src="..."></td>
</tr>
</table>


now the TD is, if possible, 50% of the table width. And the table width
is 70% of its container, wich could be the <body>.

================================

If you have more tables or td's or img's that you want to have different
measurements assigned to, work with css classes:


<style>
..tableclass {width:70%;margin-left:15%;}
..tdclass {width:50%;}
..imgclass {width:100%;}
</style>

<table class="tableclass">
<tr>
<td class="tdclass"><img class="imgclass" src="..."></td>
<td class="tdclass"><img class="imgclass" src="..."></td>
</tr>
<tr>
<td class="tdclass"><img class="imgclass" src="..."></td>
<td class="tdclass"><img class="imgclass" src="..."></td>
</tr>
</table>

As you see no javascript at all so:
while the Q is on-topic, the A is off ...

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Ang Talunin
Guest
 
Posts: n/a
#9: Jul 20 '05

re: Another CSS & Javascript Problem


> because you specified 60%, this means that the image wil fill 60% of the[color=blue]
> container, and that is the TD:
>
> <style>
> IMG {width:60%;}
> </style>
>
> If you want to change the size of the td, and fill the td with the img,
> you have to specify:
>
> <style>
> TABLE {width:70%;}
> TD {width:50%;}
> IMG {width:100%;}
> </style>
>
> <table>
> <tr>
> <td><img src="..."></td>
> <td><img src="..."></td>
> </tr>
> <tr>
> <td><img src="..."></td>
> <td><img src="..."></td>
> </tr>
> </table>
>
>
> now the TD is, if possible, 50% of the table width. And the table width
> is 70% of its container, wich could be the <body>.[/color]

OK, so I tried and made this code::
<html>
<head>
<style>
TABLE {width:70%;}
TD {width:50%;}
IMG {width:100%;}
</style>
</head>
<body >

<h1>Sportdag</h1><p>
<table><tr>
<td><img src='im1.jpg' ></a>
<td><img src='im2.jpg' ></a>

So when i resize my window it should change the size of the td....well it
doesn't....
So I tried to change the value of the table-width and for 100% it enlarged
the picture, and till about 60% it made the picture smaller, but under the
60% it didn't change anything....
might that be the problem?


[color=blue]
> ================================
>
> If you have more tables or td's or img's that you want to have different
> measurements assigned to, work with css classes:[/color]
I know that, but that's not the case.


Evertjan.
Guest
 
Posts: n/a
#10: Jul 20 '05

re: Another CSS & Javascript Problem


Ang Talunin wrote on 11 okt 2003 in comp.lang.javascript:
[color=blue]
> <h1>Sportdag</h1><p>
> <table><tr>
> <td><img src='im1.jpg' ></a>
> <td><img src='im2.jpg' ></a>
>
> So when i resize my window it should change the size of the td....well it
> doesn't....
>[/color]

You are right, I'll have to test further.
Anyone else ?



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
David Dorward
Guest
 
Posts: n/a
#11: Jul 20 '05

re: Another CSS & Javascript Problem


Ang Talunin wrote:
[color=blue]
> I don't care. If they want to see the foto's I'm displaying correctly,
> without scrollbars the just have to maximise...[/color]

Possibly a better solution would be to give the user the choice of image
size. Perhaps a background image with a scale on it showing how wide and
tall "small" and "large" (and whatever other sizes you want) will appear
and ask the user to select one. This has the added benefit that users with
large resolutions but narrow bandwidth can choose a smaller image that
downloads faster.

--
David Dorward http://dorward.me.uk/
Ang Talunin
Guest
 
Posts: n/a
#12: Jul 20 '05

re: Another CSS & Javascript Problem


> > I don't care. If they want to see the foto's I'm displaying correctly,[color=blue][color=green]
> > without scrollbars the just have to maximise...[/color]
>
> Possibly a better solution would be to give the user the choice of image
> size. Perhaps a background image with a scale on it showing how wide and
> tall "small" and "large" (and whatever other sizes you want) will appear
> and ask the user to select one. This has the added benefit that users with
> large resolutions but narrow bandwidth can choose a smaller image that
> downloads faster.[/color]

The images aren't very large, cause they already are thumbnails and linked
to the original image, so i don't think it's an option...


David Dorward
Guest
 
Posts: n/a
#13: Jul 20 '05

re: Another CSS & Javascript Problem


Ang Talunin wrote:
[color=blue][color=green][color=darkred]
>> > I don't care. If they want to see the foto's I'm displaying correctly,
>> > without scrollbars the just have to maximise...[/color]
>>
>> Possibly a better solution would be to give the user the choice of image
>> size. Perhaps a background image with a scale on it showing how wide and
>> tall "small" and "large" (and whatever other sizes you want) will appear
>> and ask the user to select one. This has the added benefit that users
>> with large resolutions but narrow bandwidth can choose a smaller image
>> that downloads faster.[/color]
>
> The images aren't very large, cause they already are thumbnails and linked
> to the original image, so i don't think it's an option...[/color]

Its quite possible. Just create images of whatever intermediate sizes you
want, and then dynamically generate the thumbnails pages with links to the
selected image size.

--
David Dorward http://dorward.me.uk/
Closed Thread