css1

Make Full Image Background With CSS

Full screen image backgrounds are a must if you are creating a portfolio or a photography website. This usually involves using a jQuery plugin, which will properly resize the image with the browser window, and do the necessary calculations so that the image covers the entire width and height of the page.

But did you know that if you are ready to sacrifice support for IE8 and below, you can have that kick ass effect only with a line of CSS? Here is how..

The background-size property

With background-size, you can tell an element how large its background image must be. Like this:

#elem{ background:url('kermit.jpg') center center no-repeat; background-size:100px 150px; }

But even more convenient, this property supports two magical values: contain and cover:

  • Contain resizes the background image so that it fits entirely in the element;
  • Cover is more interesting – it makes so that the element’s background is entirely taken up by the image. The image is resized to the smallest size that allows it to cover the element entirely (see the illustration below). This is also the property we will be using for our full screen background.

Background-size Cover vs Contain

Background-size Cover vs Contain

So all we have to do, is to set the image we want displayed full screen as a background to the html element:

html{
	/* This image will be displayed fullscreen */
	background:url('background.jpg') no-repeat center center;

	/* Ensure the html element always takes up the full height of the browser window */
	min-height:100%;

	/* The Magic */
	background-size:cover;
}

body{
	/* Workaround for some mobile browsers */
	min-height:100%;
}

And now you have your image displayed full screen! It will change its dimensions as you resize the window or change the orientation of mobile devices. It works on all recent desktop and mobile browsers (without IE8 and below as mentioned above).

Related Posts


15 thoughts on “Make Full Image Background With CSS

  1. kore dizileri izle

    Truly essential publish admin fantastic 1 i bookmarked your website page see you in next website post.

    Reply
  2. Warner Mclaws

    I simply want to say I’m very new to blogs and seriously liked your web blog. More than likely I’m want to bookmark your website . You certainly come with great articles and reviews. Thanks a lot for sharing with us your web site.

    Reply
  3. Werner Molinski

    I just want to tell you that I am just newbie to blogging and site-building and truly loved this web-site. Probably I’m going to bookmark your website . You really come with remarkable well written articles. With thanks for revealing your website page.

    Reply
  4. Donte

    i bookmarked you in my browser admin thank you a lot i will probably be searching for your up coming posts

    Reply
  5. fkawau

    I’ve been browsing online more than three hours today, yet I never found any interesting article like yours Make Full Image Background With CSS | Web Duos. It is pretty worth enough for me. In my opinion, if all site owners and bloggers made good content as you did, the internet will be a lot more useful than ever before.

    Reply
  6. hduejsgeyej

    This is the correct Make Full Image Background With CSS | Web Duos blog for anyone who wants to assay out out roughly this matter. You remark so more its virtually debilitating to discourse with you (not that I real would want…HaHa). You definitely put a new gyrate on a message thats been graphical nearly for age. Fastidious push, just zealous!

    Reply
  7. fkawau

    I’ve been browsing online more than 3 hours today, yet I never found any interesting article like yours Make Full Image Background With CSS | Web Duos. It is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the net will be a lot more useful than ever before.

    Reply
  8. asphalt 7 apk

    Make Full Image Background With CSS | Web Duos I was suggested this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my problem. You are wonderful! Thanks! your article about Make Full Image Background With CSS | Web DuosBest Regards Shane

    Reply
  9. traduceri germana romana

    The author dealt with several curious points in this article. I found it by using Msn and I’ve got to admit that I am now subscribed to your blog site, it is very great (;

    Reply
  10. Chance Gapinski

    I simply want to tell you that I am beginner to blogging and site-building and really loved your blog site. Probably I’m want to bookmark your website . You certainly come with really good article content. With thanks for sharing your blog site.

    Reply
  11. comcast miami

    There may be noticeably a bundle to learn about this. I assume you made certain nice points in features also.

    Reply
  12. Keneth Mckenny

    I just want to tell you that I am just very new to blogging and absolutely savored your web blog. Most likely I’m going to bookmark your site . You definitely come with superb well written articles. Bless you for sharing your webpage.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *


*