20

I need to know how to get the background image to not be blurry when text is over it in CSS as it spoils the look of my website if it's blurry.

My CSS is:

background: #ff0000 url(img/rain.jpg) top center repeat-y; 
background-size: 100%; 

But when I load it up where there is text that line goes blurry and I don't want it to so how do I do this?

Fiddle example

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Josh Keighley
  • 215
  • 1
  • 2
  • 7

6 Answers6

51

Try to add:

image-rendering: -webkit-optimize-contrast;
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
Kirill A
  • 519
  • 5
  • 13
12

Here's the cross browser technique:

 image-rendering: crisp-edges;
 image-rendering: -moz-crisp-edges;          /* Firefox */
 image-rendering: -o-crisp-edges;            /* Opera */
 image-rendering: -webkit-optimize-contrast; /* Webkit (non-standard naming)*/
 -ms-interpolation-mode: nearest-neighbor;   /* IE (non-standard property) */
Ric Flair
  • 387
  • 3
  • 5
11

Try adding this to the code: image-rendering: pixelated; For me it worked perfectly. you can also try - image-rendering: -webkit-optimize-contrast;

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Nurealam Sabbir
  • 365
  • 3
  • 4
6

You can use image-rendering: pixelated. Here is an example from the Mozilla Developer Network:

.pixelated {
  image-rendering: pixelated;
  -ms-interpolation-mode: nearest-neighbor;
}

https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering

https://jsfiddle.net/9dtj2wkq/

tosh
  • 5,222
  • 2
  • 28
  • 34
5

use of background-size: cover;background-position:50% 50%; will help you..

* {
font-family: Calibri, Comic Sans MS, Serif;
background: #ff0000 url(http://www.coolguysite.co.uk/blog/templates/default/img/rain.jpg)   top center repeat-y;
background-size: cover;
background-position:50% 50%;
}

UPDATED FIDDLE

RbG
  • 3,181
  • 3
  • 32
  • 43
-8

I got it by doing:

background: transparent;

to the h2 and p elements.

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Josh Keighley
  • 215
  • 1
  • 2
  • 7