Monday, 2 October 2023

CSS Background Styling

 CSS Background Styling

The CSS background properties are used to add background effects for elements.

CSS most common background properties are:


  • background-color
  • background-image
  • background-repeat
  • background-attachment
  • background-position


1. CSS Background Color

The background-color property specifies the background color of an element.

You can set the background color for any HTML element.


With CSS, a color is most often specified by:


a valid color name - like "red"

a HEX value - like "#ff0000"

an RGB value - like "rgb(255,0,0)"



2. CSS Background Image

The background-image property specifies an image to use as the background of an element.

By default, the image is repeated so it covers the entire element.

The background image can also be set for specific elements, like the <p> element.





3. CSS Background-repeat

The background-image property repeats an image both horizontally and vertically.

Some images should be repeated only horizontally or vertically, or they will look strange.






4. CSS Background-position

The background-position property is used to specify the position of the background image.



5. CSS Background Attachment

The background-attachment property specifies whether the background image should scroll or be fixed (will not scroll with the rest of the page).



Code:-

Output:-



Written by:  W.A. Eranga Dewmini

No comments:

Post a Comment

Java Script Learning

 Introduction to JavaScript JavaScript is the programming language used by front-end web developers to instruct the browser to add behaviors...