Why doesnt width: auto work on my images? wordpress

Hi

I have this:

<div>
<img />
</div>

CSS:

div{
position: relative;
}

img{
position: absolute;
height: 100%;
width: auto;
left: 0;
top: 0;
}

Shouldn’t the image ignore its containers width with this CSS? Because its still taking the width of its container, which is messing up the proportions.

It does?

<!DOCTYPE HTML>
<html>
<head>
<title>Untitled Document</title>
<style>

div{
position: relative;
height:400px;
background:red;
}

img{
position: absolute;
height: 100%;
width: auto;
left: 0;
top: 0;
}
</style>
</head>

<body>
<div>
<img src="http://placehold.it/150x142">
</div>

</body>
</html>

Hi,

Yeah it SHOULD work, but it don’t=/ That’s why i wonder if this has something to do with wordpress?

Position:absolute shrink-to-fits the elements. If it has auto width it will shirnk to fit, in this case, it will take on the width of hte image. This is expected behavior.

If the above behavior is not happening then there is some other issue. Most probable that there is a width set. We would need a website to confirm.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.