When my pictures with equal height, but when make img width: 100%;,things went wrong.the picture can't equal height.
I don't think this is an easy question to me.
I don't understand why picture with same height, can't render by browser equal height.
here is jsfindle.
the effect with no pictures
But when I put pictures to img:src, things got bad.
After all, I want it make equal view though different device,not only pc.But,...
I puzzled, what's the point to this question?
In the example you set the height of the FRAME to 35 and that doesn't change from one div to the next. The height is not set for the image in the CSS, but the MAX-HEIGHT is, so the height can be changed, but will not go over the max-height. Same with the width, it is not set.
When you change the height in the html tag, html keeps the restraints of the image size. If you remove 20 percent of the height, it will automatically remove 20 percent of the width unless you tell it not to by setting the width you want.
Try this:
<div class="frame">
<img src="http://jsfiddle.net/img/logo.png" height="250" width="250" />
</div>
<div class="frame">
<img src="http://jsfiddle.net/img/logo.png" height="25" width="250" />
</div>
The height will change, but the width will not. But of course the width has it's MAX-WIDTH set to 160px so even though this html code says 250, it still wont go over 160.
I think this is what you were asking, if not, then I apologize.
Related
My image now: <img src="image.webp" width="100%">
I know, I should use this to prevent cumulative layout shift: <img src="image.webp" width="150" height="200">
But this way it can't fill the div in all screen resolutions, so it is not responsive anymore.
What should I do?
Thank you.
You are probably looking for the css properties max-width and max-height. They will prevent the image from getting any bigger that the width and height you specify, but if the viewport is too small and the would overflow, then they default to the regular width and height, which if not declared would default to auto (but you can also use the width="100%" that you are already using, which is also responsive) and fit on your screen.
You probably want something more robust to make your entire layout re-arange nicely, but max width and height are a good place to start looking
I'm loading multiple thumbnails per page, between 50 or 100. Even if it's not necessary, i do want to supply some sort of height and width to the <img> element so it doesn't causes a visual reflow of the page once the images load.
I don't know the exact width or height of each image. I only know, for sure, that the image width and height will never be greater than 125px.
So, i can have images like 125x125, 100x80, 45x 90, etc... but never greater than 125 in width or height.
Is there a technique to prevent visual reflow of the page knowing what i've just mentioned?
Thanks
If I understand you correctly, you should wrap your element in a (or block type element) and set the min-width and min-height on the new div. If you want it to only take up the minimum space necessary, use 45 and 90 as the minumum. if you want it to take up the total possible space, use 125 as the minumum. like so:
<div class="img-holder>
<img src="path/to/image" />
</div>
And in your css:
.img-holder {
min-width: 45px;
min-height: 90px;
}
I have an image tag. I tried to set the max height and width property to 600 px. Now if the image size is less than it, it increases the image size. I only want to have the max height and width only if image is more than 600 px.
<img src="8.jpg" style="max-height: 600px;max-width:600px;/">
It works proper, can you make a fiddle with wrong example?
<img src="http://www.waltereul.de/walter-eul-pictures/walter-eul_100x100_10.jpg" style="max-height: 200px;max-width:200px;/">
<img src="http://www.zenimax.com/jpn/fallout3/images/avators/100x100falloutav-vb.gif" style="max-height: 200px;max-width:200px;/">
example
For me it looks like your img-tag is affected by another css-rules which affect the width/height of your images. I would suggest to use the developer tools of your browser to check which css-rules affect your img-tags (Tutorial if needed: https://developer.mozilla.org/en-US/Learn/Discover_browser_developer_tools).
Also in your code example above, the slash should be outside of your style-attribute, like this:
<img src="8.jpg" style="max-height: 600px;max-width:600px;" />
max-width purpose is to limit a large resolution image into specified size.
so, basically max-width itsef can't force a smaller images to enlarge.
i bet the images are affected by other CSS. as stated:
"The max-width property is used to set the maximum width of an element.
This prevents the value of the width property from becoming larger than max-width." - http://www.w3schools.com/cssref/pr_dim_max-width.asp
please try This one:
One method
<img src="8.jpg" style="max-height: 200px;max-width:200px;/">
another one method like this:
<img src="8.jpg" />
Css Code:
img{
width:100%;
max-width:600px;
}
I'd like to have an image to have either a height of 725 or a width of 500 and maintain it's aspect ratio. When I have images with a height of over 725 and thinner than 500 they get stretched out to fit a width of 500.
What is the best way to do this?
Below is what I am doing now:
<asp:Image Height="725" width="500" ID="img_DocPreview" />
Update:
Changed it to this but have the same problem. If I specify just the height it will maintain the aspect ratio but it exceeds the max width of 500px that i want.
<img style="height:725px;width:500px;" id="img_DocPreview" src="Images/empty.jpg" />
You can try this one
img{
max-height:500px;
max-width:500px;
height:auto;
width:auto;
}
This keeps the aspect ratio of the image and prevents either the two dimensions exceed 500px
You can check this post
editied to add support for ie6:
Try
<img style="height:725px;max-width:500px;width: expression(this.width > 500 ? 500: true);" id="img_DocPreview" src="Images/empty.jpg" />
This should set the height to 725px but prevent the width from exceeding 500px. The width expression works around ie6 and is ignored by other browsers.
If you only specify either the height or the width, but not both, most browsers will honor the aspect ratio.
Because you are working with an ASP.NET server control, you may consider executing logic on the server side prior to rendering to decide which (height or width) attribute you want to specify; that is, if you want a fixed height under one condition or a fixed width under another.
set a style for the image
<asp:Image ID="Image1" runat="server" style="max-height:1000px;max-width:900px;height:auto;width:auto;" />
You could use some CSS and with the idea of kbrimington it should do the trick.
The CSS could be like this.
img {
width: 75px;
height: auto;
}
I got it from here: another post
I was wondering if in the width and height <img> attributes, I could specify width and height as percentages?
Well, I guess that is obvious, because when I try so, it resizes, but it appears to skew the quality of my image.
Here is an example of my markup with fixed attributes:
<img src="#" width="346" height="413">
Now, while trying to scale this down, say by half, via percentages:
<img src="#" width="50%" height="50%">
I get something completely different than:
<img src="#" width="173" height="206.5">
I think I'm just fundamentally mistaking my percentage markup or something because there is a noticeable difference between my second and third example visually.
Note: it is invalid to provide percentages directly as <img> width or height attribute unless you're using HTML 4.01 (see current spec, obsolete spec and this answer for more details). That being said, browsers will often tolerate such behaviour to support backwards-compatibility.
Those percentage widths in your 2nd example are actually applying to the container your <img> is in, and not the image's actual size. Say you have the following markup:
<div style="width: 1000px; height: 600px;">
<img src="#" width="50%" height="50%">
</div>
Your resulting image will be 500px wide and 300px tall.
jQuery Resize
If you're trying to reduce an image to 50% of its width, you can do it with a snippet of jQuery:
$( "img" ).each( function() {
var $img = $( this );
$img.width( $img.width() * .5 );
});
Just make sure you take off any height/width = 50% attributes first.
You can set one or the other (just not both) and that should get the result you want.
<img src="#" height="50%">
Here is the difference:
This sets the image to half of its original size.
<img src="#" width="173" height="206.5">
This sets the image to half of its available presentation area.
<img src="#" width="50%" height="50%">
For example, if you put this as the only element on the page, it would attempt to take up 50% of the width of the page, thus making it potentially larger than its original size - not half of its original size as you are expecting.
If it is being presented at larger than original size, the image will appear greatly pixelated.
Try use scale property in css3:
75% of original:
-moz-transform:scale(0.75);
-webkit-transform:scale(0.75);
transform:scale(0.75);
50% of original:
-moz-transform:scale(0.5);
-webkit-transform:scale(0.5);
transform:scale(0.5);
width="50%" and height="50%" sets the width and height attributes to half of the parent element's width and height if I'm not mistaken. Also setting just width or height should set the width or height to the percentage of the parent element, if you're using percents.
Given the lack of information regarding the original image size, specifying percentages for the width and height would result in highly erratic results. If you are trying to ensure that an image will fit within a specific location on your page then you'll need to use some server side code to manage that rescaling.
From W3Schools
The height in percent of the containing element (like "20%").
So I think they mean the element where the div is in?
There is actually a way to do this with html only. Just sets:
<img src="#" width height="50%">