Using CSS’s Background Property

Published October 24, 2016 by CSS Newbies.

CSS’s background property actually covers a whole lot of other properties, meaning that the background property is actually sort of all-inclusive and will take up to 8 values. The background property shorthand covers the background-color (for when you want to define a color as the background of an element), background-image (for when you want to use an image as the background of an element), background-repeat (do you want the background image to repeat vertically or horizontally?), background-attachment (how do you want the background to be positioned in regards to the viewport?), background-position (where do you want your background to be positioned in regards to the surrounding elements?), background-origin (yet another positioning property), and background-clip (to specify the content limit of the background). Check out the syntax and the order of the properties in the example below to learn how to use the property for yourself. All of the properties included in the background shorthand can be defined on their own, but your code will look a lot cleaner if you just use the shorthand:

background: [background-color] [background-image] [background-repeat] [background-attachment] [background-position] / [background-size] [background-origin] [background-clip];

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>