Backgrounds

CSS3 contains several new background attributes; and moreover, in CSS3, some changes are also made in the previous properties of the background; which allow greater control on the background element.

The new background properties added are as follows.

The background-clip property

The background-clip property is used to determine the allowable area for the background image.

If there is no background image, then this property has only visual effects such as when the border has transparent regions or partially opaque regions; otherwise,the border covers up the difference.

Syntax

The syntax for the background-clip property are as follows:

background-clip: no-clip / border-box / padding-box / content-box;

Values

The values for the background-clip property is as follows:

  • border-box: With this, the background extends to the outside edge of the border
  • padding-box: With this, no background is drawn below the border
  • content-box: With this, the background is painted within the content box; only the area the content covers is painted
  • no-clip: This is the default value, same as border-box

The background-origin property

The background-origin property specifies the positioning of the background image or color with respect to the background-position property.

This property has no effect if the background-attachment property for the background image is fixed.

Syntax

The following is the syntax for the background-attachment property:

background-origin: border-box / padding-box / content-box;

Values

The values for the background-attachment property are as follows:

  • border-box: With this, the background extends to the outside edge of the border
  • padding-box: By using this, no background is drawn below the border
  • content-box: With this, the background is painted within the content box

The background-size property

The background-size property specifies the size of the background image.

If this property is not specified then the original size of the image will be displayed.

Syntax

The following is the syntax for the background-size property:

background-size: length / percentage / cover / contain;

Values

The values for the background-size property are as follows:

  • length: This specifies the height and width of the background image. No negative values are allowed.
  • percentage: This specifies the height and width of the background image in terms of the percent of the parent element.
  • cover: This specifies the background image to be as large as possible so that the background area is completely covered.
  • contain: This specifies the image to the largest size such that its width and height can fit inside the content area.

Apart from adding new properties, CSS3 has also enhanced some old background properties, which are as follows.

The background-color property

If the underlying layer of the background image of the element cannot be used, we can specify a fallback color in addition to specifying a background color.

We can implement this by adding a forward slash before the fallback color.

background-color: red / blue;

The background-repeat property

In CSS2 when an image is repeated at the end, the image often gets cut off. CSS3 introduced new properties with which we can fix this problem:

  • space: By using this property between the image tiles, an equal amount of space is applied until they fill the element
  • round: By using this property until the tiles fit the element, the image is scaled down

The background-attachment property

With the new possible value of local, we can now set the background to scroll when the element's content is scrolled.

This comes into action with elements that can scroll. For example:

body{background-image:url('example.gif'),background-repeat:no-repeat;background-attachment:fixed;}

Note

CSS3 allows web designers and developers to have multiple background images, using nothing but just a simple comma-separated list. For example:

background-image: url(abc.png), url(xyz.png);

Borders

The border property allows us to specify the style and color of an element's border, and with the help of CSS3 we have stepped into the next level.

With CSS3, we can create rounded borders, add shadow, and use an image as a border without using various design programs such as Photoshop.

The new border properties added are as follows.

The border-radius property

Creating rounded borders using CSS was never easy. There were numerous methods available, but none of the approaches were straightforward. Moreover, it was necessary to use vendor prefixes for both WebKit and Mozilla, in order to apply the style correctly.

The border-radius property can be applied to customize buttons. We can also apply border-radius to individual corners. And with the help of this property, we can create rounded borders easily.

Syntax

The syntax for the border-radius property is given as follows:

border-radius: 1-4 length / % ;

Values

Following are the values of the border-radius property:

  • length: This defines the size of the radius of the circle
  • %: This defines the size of the radius of the circle using percentage values

The box-shadow property

The box-shadow property allows designers and developers to create multiple drop shadows easily. These can be outside or inside the boxes, specifying values for color, size, blur, and offset.

By simply declaring box-shadow once, we can use both outer and inset versions, separated by a comma.

Syntax

The syntax for the box-shadow property is as follows:

box-shadow: h-shadow v-shadow blur spread color inset;

Values

The following shows the values of the box-shadow property:

  • inset: This changes the outer (outset) shadow to the inner shadow
  • <h-shadow>, <v-shadow>: This specifies the position of the shadow
  • <blur>: The larger this value, the bigger the blur
  • <spread>: This specifies the size of the shadow
  • <color>: This specifies the color of the shadow

The border-image property

The border-image property is a little tricky, but it allows us to create boxes with custom borders. With this feature, you can define an image to be used as a border instead of the normal border.

We can create decorative borders beyond simple rounded corners with images or even with gradients.

This feature is actually split into a couple of properties:

  • border-image
  • border-corner-image

Syntax

The syntax for the border-image property are as follows:

border-image: <source><slice><width><outset><repeat>;

Values

The values of the border-image property is given as:

  • source: This specifies the image to be used for the border.
  • slice: This specifies the inward offsets of the border.
  • width: This specifies the width of the border.
  • outset: This specifies how much the border image area extends beyond the border box.
  • repeat: This specifies whether the border should be stretched or not. If yes, then whether it is rounded or stretched.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.215.117