display image full size css
Add these properties to your .header
class. But I am not sure if this'll work in old browsers.
background-repeat: no-repeat;
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
Update
If your height is less then the image height, you will loose dimension ratios. In this case your image will be stretched. You can define width and height like this background-size: 300px 150px;
as described here.
Moreover you can use cover
and contain
options with background-size
property. As your container height is less then the image you have to rely on this otherwise set width height screw background image.
For more reference please see this link.
sukhvir
Updated on March 09, 2020Comments
-
sukhvir about 4 years
I am trying to display this image in my blog full size : http://i.imgur.com/BruV8Hk.jpg
However it gets cropped ... i don't know why. I have tried rechecking the
.header
boundaries and I can't see where I would be limiting the size available for the image.Here is the codepen for the site : http://codepen.io/anon/pen/grLED
Please help
EDIT:
Just to clarify .. I would like my
.header
container to be big enough to house that image in fullEDIT 2:
so i just did this : http://codepen.io/anon/pen/vJyFn to get the desired result ... can it be done without all those
<br>
?-
Ruddy over 9 yearsAdd
background-size:cover;
to.header
-
Benjamin over 9 yearsPosible duplicate
-
Fergoso over 9 yearsuse
background-repeat:no-repeat;
andbackground-position:center center;
-
-
sukhvir over 9 yearsthat one didn't do anything
-
sukhvir over 9 yearsit still doesn't show full picture .. here is the edited codepen with your suggestion : codepen.io/anon/pen/Loect
-
sukhvir over 9 yearslink you posted .. is the same one i posted in my original post .. if you have made any changes to file .. press 'fork' on top and post the new url
-
Siyam Kumar over 9 yearstry using 'background-size:auto 100%;'
-
sukhvir over 9 yearsdo you mind making changes to my code pen please to see if it works
-
sukhvir over 9 yearswhich
height
are you referring to? Myheight
for the.header
section is set to100%
... -
Bilal over 9 yearsSuppose height of
header
in the page is200px
and you image height is1000px
. This is what I am saying that.header
height is less than image height. -
Bilal over 9 yearsAs you updated your question, how can you make header of page to full height of screen? If this is the case it should not be your header. Attach background to
body
or containerelement
. -
sukhvir over 9 yearsok you missed the point ... i don't want that image to be the background of the entire site ... i just want it to be the background of the
.header
container .. see edit to the original question -
ThatMSG over 9 yearsalight, sry for that. All you have to do is add: background-repeat: no-repeat; background-position: center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; to your .header class
-
sukhvir over 9 yearsi don't want the header to be full height of the screen .. i just want it to be big enough to house that image in full ... isn't
.header
like any other container whose dimensions can be varied with contents in it -
sukhvir over 9 yearsi am trying to make it look like this: bitofpixels.com/blog/…
-
Bilal over 9 yearsThen you should user
<img />
tag instead of background. -
sukhvir over 9 yearsif I do that .. the text will be displayed below the image .. i want it to be overlayed over the image
-
Bilal over 9 yearsSet position of text using
absolute
.