Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crop background-image using CSS

Tags:

html

css

I have a background-image on the body tag which is around 500px high. This is fine for the index page, however on other pages it does not look right. I want to be able to crop the background-image on other pages to around 300px high, but still using the background-image in the body tag.

Is this possible using just CSS?

like image 834
jcrowson Avatar asked Oct 12 '11 10:10

jcrowson


2 Answers

Make bg image 300px height, not crop, but scale:

background-size: auto 300px;

But you can't crop to an area smaller than the tag where background is set. You have to write a tag inside with the desired height set bagground there and then crop:

 background-size: cover;
like image 195
Max Oriola Avatar answered Oct 25 '22 09:10

Max Oriola


background-size http://www.css3.info/preview/background-size/

like image 2
Alistair Laing Avatar answered Oct 25 '22 10:10

Alistair Laing