# Is this CSS for background imagery good?

**URL:** https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358
**Category:** Support
**Created:** [October 11, 2015, 1:06am UTC](https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358 "2015-10-11T01:06:20Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Erik\_Manger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erik_manger/32/179399_2.png) [@Erik\_Manger](https://meta.discourse.org/u/Erik_Manger)
#### Post date: [October 11, 2015, 1:06am UTC](https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358/1 "2015-10-11T01:06:20Z")

</div>

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('https://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;
}

```

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 11, 2015, 2:13am UTC](https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358/2 "2015-10-11T02:13:08Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [October 11, 2015, 2:53am UTC](https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358/3 "2015-10-11T02:53:21Z")

</div>

Looks good to me 👍

---

<div class="post-metadata">

### Author: ![Roxelle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/roxelle/32/46924_2.png) [@Roxelle](https://meta.discourse.org/u/Roxelle)
#### Post date: [October 11, 2015, 2:09pm UTC](https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358/4 "2015-10-11T14:09:01Z")

</div>

Good man! I can use in my site. Thanks! 😋

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 11, 2015, 3:59pm UTC](https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358/5 "2015-10-11T15:59:53Z")

</div>

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:

```css
// 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:

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

```

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

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:45pm UTC](https://meta.discourse.org/t/is-this-css-for-background-imagery-good/34358/6 "2024-06-08T12:45:57Z")

</div>

This topic was automatically closed after 3163 days. New replies are no longer allowed.
