Fit a large size image in viewport without sliding - html

I have tried to add the image in the page, but end up the image is too big for the viewport.
enter link description here
I tried some way that has been posted put none of them working. Is there anyway to do this without resizing the image by using fixed width/height

try to use
width : 100%
Here some update on your codepen
https://codepen.io/anon/pen/vjMWYo

try using max-width:100% on image. Something like this:
img {
max-width: 100%;
}
<img src="http://via.placeholder.com/1700x400" />

Related

is there any other way to fit the bg using html

I have an JPG image with size 1024 x 724. My page size is not fixed. My requirement is: If I resize the page then the background image should also resize and fit to the page.
You should do this with backgroud-size in css
If you'd like to use CSS3, you can do it pretty simply using background-size, like so:
background-size: 100%;
in you div you can add the style directly without using a css external file
<div style ="background-size: 100%;" ....> .... </div>
You need to make a 100% width b aground which must cover up you complete background.
So please add this css in you style.css file.
html {
background: url(yourimage.jpg);
background-size:cover;
}

Image helper unwanted resizing

When I use my image-tag helper the image on the page is always smaller than the size of the image. Is this a rails thing or am I overlooking something? Even when setting image height to 100%, I can't get the full sized image. Any ideas??
Most probably the image size is predefined in your stylesheet/css, take a look there.
Or you could try: image_tag("/icons/icon.gif", height: '32', width: '32')
Resource is here: http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-image_tag
You can try this code
<img src="img_location" alt="" style="width:100%; Height:100%;"/>
If your image size predefined by your css then it solve.

CSS applying Max-height and Auto height property at the same time for an image

How do I set the the max-height:270px and height:auto simultaneously such that if a content(image) is too large it should shorten its dimensions and put it under 270px, else it should be an auto height.
I tried with overflow-Y but I dont want a scrollbar, just a mini version of the pic. How can I do that?
CHANGED CODE :: TRY IT
img{
height:100%;
max-height:270px;
}
use like this
height:auto;
max-height: 270;
Overflow:hidden;
max-height will restrict your images height to that px if the image height is higher than that.
giving any specific height will scale the image if the height amount is less than the image height.
Overflow hidden will hide the scroll bar.
Use like this:
height: 0; /*rather than auto*/
max-height: 270px;
do not apply a width in the image tag. set your css to max-width:100%; max-height:100%;
Also, read this http://unstoppablerobotninja.com/entry/fluid-images
You would just do this:
<img style="max-height:270px" src="500x500.png" alt="I am resized to 270x270">
<img style="max-height:270px" src="200x200.png" alt="I am not resized">
By not setting a height/width it allows the browser to display the image at it's native size up to the limit you set via max-height.
While leaving out the h/w is not best practice, it accomplishes easily what you are trying to do and will just take a fraction of a second longer to load the page since the browser has to calculate each image size before displaying it.
Example: jsFiddle
As far as i understand you have 2 code one work for google chrome and another for all other browsers how to combine them.(if not you can edit my code alittle bit to satisfy your needs)
You could try something like this:
<?PHP if($browser == "Chrome"){ ?>
<!--HTML Code for Chrome browser-->
<?PHP }else { ?>
<!--Code for other browsers-->
<?PHP } ?>
This would help for cross browsers scripts

How come the image.height is not the proper size?

When I have an image from 950x500 and output it like so:
<img src="http://full/url/to/image.png" />
There is a weird 3px in height space below the image. When asking javascript about it, it will indeed say the size is 950x503. While the image is really (check multiple times) 500 in size. It appears that the image tag does this how can this be fixed?
Note that the image must also remain to function dynamic. So if I were to set width of the image to 100% the height will resize accordingly.
Try this instead of putting display :block; beacuse this gonaa effect all the image tag though there is no harm, but the right way is this :
<img src="http://full/url/to/image.png" height="950" width="500"/>
Never mind, the answer is, set your image display on block like so:
img { display: block; }

Stretching images when using as background image

I was trying to set an image as background image for my django application. But when i set it, it is getting displayed as tiled image. ie without actually stretching the image, same image is tiled and shown 4 times. Can somebody tell me how to stretch the image and set it as a background image. I will paste my code here. I am sure some attribute must be there setting this, which i couldnt find on googling.
<body bgcolor=" #408080" background="/static/paper.jpg" background-size: 100%; >
Instead of using a background image on the body tag you should add a image tag right below body, set the position to absolute and a low z-index and then have width=100% and height=100%.
You need to apply this as a style, not as an attribute. That will work if your browser supports CSS 3:
style="background: url(/static/paper.jpg); background-size: 100%;"
Some background info:
http://css-tricks.com/perfect-full-page-background-image/
http://css-tricks.com/how-to-resizeable-background-image/
In short: no, you can't stretch the background image with html/css1/css2, you're only options is to either use css3 ( witch is not fully suported by all browsers ) or to use background-attachment and background-repeat css porperties to achieve an alternative result …
Another option would be to use an img tag as a background using z-index css proprety however you'll find it dificult to get it working proprely in all major browsers .
You can stretch your background to 100% width and height by putting your image in an <img> tag and give it a z-index of -1 so it acts like a background and is behind everything else. This works in all browsers.
<img src="..." />
img{
position:absolute;
z-index:-1;
width:100%;
height:100%;
}
If you do not want to break the aspect ratio, just set either width or height and not both.
Check working example at http://jsfiddle.net/UXBRM/1/
Edit your image with paint. Click image and save your image according to your need.
This will work in any html , surely.
As others mention, you should always try to define as much of the attributes in your css and not directly where you have the path to the image itself. This is how it was done way back and is deprecated and probably why it is not working.
use the img src="poefwpf.png" and maybe a to easy edit in your css:
#imgex img {
width: 100%;
height: 100%;
(maybe also z-index:-1;)
}