css question

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
 
J

Just Me

set the with attribute of the element style to 80%

var myElement= document.getElementById("elementID");
myElement.setAttribute("width","80%");
 
N

Nick Chan

could u do something like this?

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

Tem

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?
 
K

Kevin Spencer

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
 
T

Tem

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
 
K

Kevin Spencer

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
 
S

Savio

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,
 

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

Top