ph91.de
  • Home
  • About me
  • Categories
    • Software Development
    • New Zealand
    • Music
    • Tech & IT
    • Sports
    • Dublin
    • Junk
  • Contact
  • Disclaimer
ph91.de
ph91.de
  • Home
  • About me
  • Categories
    • Software Development
    • New Zealand
    • Music
    • Tech & IT
    • Sports
    • Dublin
    • Junk
  • Contact
  • Disclaimer
  • Software Development

CSS Hack for Background Images

  • 7. November 2014
  • Philipp

I recently came across the problem of full-screen background images in CSS. CSS3 offers a value cover which works pretty good on desktop browsers, but for the mobile version of Chrome a small hack is needed to make it work.

W3schools decribes the cover value for background-size as follows

Scale the background image to be as large as possible so that the background area is completely covered by the background image. Some parts of the background image may not be in view within the background positioning area.

Basically that sounds pretty good. I used this value for the background image on my site to display the B/W image of the beach as a full-screen background. In IE, Firefox and Chrome the results were as expected. But when I opened the website on my Chrome mobile browser I was a bit shocked. During page transitions the background looked really weird and the size was also changing….pretty weird. Here two screenshots:

Background image without the hack
Backgrund image without the hack

I did some research on this problem and quickly found a solution. The mobile chrome browser obviously needs width and height values for the node which should have the full-screen background. So I added something like this to my html-tag:


html {
height:100%;
min-height:100%;
width: 100%;
/*background... rest of background specification*/
}

After these small changes to background-image looks like intended:

wpid-screenshot_2014-11-07-13-46-12.png

Related Topics
  • background-size
  • cover
  • css
  • full-screen
  • hack
Philipp

Previous Article
  • Music

David Rodigan MBE = LEGEND

  • 7. November 2014
  • Philipp
View Post
Next Article
  • Dublin
  • Junk

Catching up with the Dailies

  • 10. November 2014
  • Philipp
View Post

Leave a Reply

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

Dev profiles
  • BitBucket
  • Github
  • Stackoverflow
Side Projects
  • NMF
  • Speed-kini.de
  • Sudoku Solver
  • Windwarner
Archive
ph91.de
Blog by Philipp Schreitmüller

Input your search keywords and press Enter.