If asked what makes all men live in fear, the answer is uncertain. No one is revealing, but Curiosity kills the cat. Nine of the 10 women agreed. Advertisers try their best to make us feel inadequate, but will tell us that we can improve. Yes, gentlemen .... Size is important.
What I'm saying is background-size
. The properties in CSS background-size
allow the programmer to decide how to display the specified elements. MooTools programmer Christoph Pojer used technology on his website background-size
to make his avatar "completely covered" on the page--even on the phone--on his browser. Let's take a look at how the magical background-size
properties are used.
background-size
CSS Properties
This background-size
property has several predefined values, but you can also use numbers like other size properties:
- contain: contains, the entire background map is to be contained within the element, there is no beyond the part.
- cover: Overwrite, background to overwrite all areas of the element, no white space appears.
- length/percentage: numeric value
Whether you believe it or not, the most interesting part is when its value is length and percentage. Here background-size
are a few examples to illustrate several different uses:
/* Base Header Classes */#header {/* Header dimension! */height:350px;/* additional background Properties */background-re Peat:no-repeat;background-position:center center;/* Some box shadow for good fun */-webkit-box-shadow:rgba (0,0,0,0.20) 0 10px 10px;-moz-box-shadow:rgba (0,0,0,0.20) 0 10px 10px;box-shadow:rgba (0,0,0,0.20) 0 10px 10px; /* Overwrite cover */#header. Flex {/* Size matters */-webkit-background-size:cover;-moz-background-size:cover; Background-size:cover;} /* contains contain */#header. Flex {/* Size matters */-webkit-background-size:contain;-moz-background-size:contain; Background-size:contain;} /* Flex, Fun */#header. Flex {/* Size matters */-webkit-background-size:100% auto;-moz-background-size:100% Auto;backgro und-size:100% Auto;}
Christoph used the last example on its website.
background-size
The magic lies in its ability to adjust itself. I used to worry that when the browser window changes, there will be unpredictable changes to the page when a Resize event occurs. But background-size
it can adapt to the size of the client browser. background-size
supported in Firefox, Safari, Google Chrome, Opera, and ie9+.
Do you think this technology is worth it? Will it be used on your page?