Is this CSS for background imagery good?


(Erik Manger) #1

Hi,

A friend of mine gave me this code to use on Discourse for background imagery. It works fine but I was wondering if the way it is coded could be perfected a little more?

// solid white background for content
body:before {
    display: inline-block;
    width: 1125px;
    min-height: 100%;
    height: inherit;
    background-color: white;
    content: " ";
    position: fixed;
    left: 50%;
    right: 0;
    transform: translate(-50%, 0);
    -webkit-transform: translate(-50%, 0);
}

// compatibility for all devices
@media (max-width: 1139px) and (min-width: 1000px)
{
    body:before {
        width: 1010px;
    }
}

body {
  background: url('http://i.imgur.com/12WWafT.jpg') no-repeat 50% 50% fixed; 
  background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  -webkit-background-size: cover;
}

(Simon Cossar) #2

That’s neat! I assume the point of it is to avoid having the background image flash while the page is loading. I think that problem could also be fixed by changing the Discourse styles so that the page doesn’t collapse during the loading event.


(Kane York) #3

Looks good to me :+1:


(Marco) #4

Good man! I can use in my site. Thanks! :yum:


(Simon Cossar) #5

I’m using this on the forum I’m putting together now. I don’t think you need the media queries section if you are using a recent version of Discourse:

// compatibility for all devices
@media (max-width: 1139px) and (min-width: 1000px)
{
    body:before {
        width: 1010px;
    }
}

Also, the width in the first part should be 1126px instead of 1125px.

The margin needs to be adjusted for the admin section. It is a problem in the Discourse css. Until that gets fixed, you can use this to keep all the admin section inside of its wrapper:

.admin-contents {
    margin-left: 0;
    margin-right: 0;
}

The ‘Categories’ page will need a bit of work to look good like this.