Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CSS3 offer a "minimum-size" property for "background"?

Tags:

I'm using

background-size: 100%; 

To fit my background image (in the body-tag) to the browser window.

But is there a CSS3 background-property to set a minimum-size?

Or will I need some div-"trick" like:

<div id="bg">     <img src="images/bg.jpg" alt=""> </div>  #bg {     position:fixed;     top:-50%;     left:-50%;     width:200%;     height:200%; } #bg img {     position:absolute;     top:0;     left:0;     right:0;     bottom:0;     margin:auto;     min-width:50%;     min-height:50%; } 
like image 964
francisMi Avatar asked May 21 '12 09:05

francisMi


People also ask

What is background-size property in CSS?

The background-size CSS property sets the size of the element's background image. The image can be left to its natural size, stretched, or constrained to fit the available space.

Which CSS property can be used to resize or scale a background image?

The background-size CSS property lets you resize the background image of an element, overriding the default behavior of tiling the image at its full size by specifying the width and/or height of the image. By doing so, you can scale the image upward or downward as desired.

What is the CSS3 background-size property?

Fortunately, CSS3 introduces the background-size property which allows backgrounds to be stretched or squashed. It’s ideal if you’re creating a template using Responsive Web Design techniques. There are several ways to define sizing dimensions — view the CSS3 background-size demonstration page.

What is the difference between background-size and cover?

The background-size property also accepts a contain keyword. This scales image so it fits the container. In other words, the image will grow or shrink proportionally but the width and height will not exceed the container’s dimensions: background-size also accepts the cover keyword.

Does the width of the background image depend on the container?

If a percentage is used, the dimension is based on the containing element — NOT the size of the image, e.g. The width of the background image therefore depends on the size of its container.

What are the different types of background properties?

Definition and Usage. The background property is a shorthand property for: background-color. background-image. background-position. background-size. background-repeat.


1 Answers

I think you are looking for

background-size: contain; 

OR

background-size: cover; 

The difference being that cover specifies that the background image should be as small as possible while maintaining its aspect ratio. contain on the other hand specifies that the background image should be as large as possible.

See the MDN documentation here.

like image 87
Raab Avatar answered Nov 06 '22 01:11

Raab