css question

  • Thread starter Thread starter Tem
  • Start date Start date
T

Tem

Is this possbile with css or do I need to use javascript? If so how?

<div class="a1" style="width:100%"><img src="test.jpg" /></div>

The width of the div is a variable. Can I scale the img accordingly?
img width is 80% of the width of the div


Tem
 
set the with attribute of the element style to 80%

var myElement= document.getElementById("elementID");
myElement.setAttribute("width","80%");
 
could u do something like this?

<div class="a1" style="width:100%"><img src="test.jpg" style="width:
80%" /></div>
 
That won't work because I need to set the width of the image, 80% of the
width of the parent element, the div.
Can this be done with CSS?
 
If you had tried Nick's suggestion, you would have seen that this is exactly
what it does.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
Thanks. how do I center the image in the div?

Kevin Spencer said:
If you had tried Nick's suggestion, you would have seen that this is
exactly what it does.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
Put the image inside a div with the div's width style set to "1px", and its'
left-margin and right-margin styles set to "auto". Put the div inside the
div you want to center the image in. The inner div will stretch its' width
to accomodate the image and be centered in the outer div.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
Is this possbile with css or do I need to use javascript? If so how?

<div class="a1" style="width:100%"><img src="test.jpg" /></div>

The width of the div is a variable. Can I scale the img accordingly?
img width is 80% of the width of the div

Why don't you apply the stype to the <img> object? :-)

<img src="a.gif" style="width:100%"/>

regards,
 
Back
Top