How to styled background – easy way
CSS backgrounds define the background effects for elements in a web page. There are several properties related to backgrounds, each offering different customization options, such as setting colors, images, position, repeat options, etc.
Here are the main background-related properties:
1. background-color: Sets the background color of an element.
2. background-image: Sets an image as the background of an element.
3. background-repeat: Specifies if/how a background image will be repeated.
4. background-position: Specifies the position of the background image.
5. background-size: Specifies the size of the background image.
6. background-attachment: Defines if a background image is fixed or scrolls with the page.
7. background (shorthand): A shorthand to set all the background properties in one go.
Example 1: Background Color
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Background Example</title> <style> body { background-color: lightblue; } </style> </head> <body> <h1>This page has a light blue background.</h1> </body> </html>
Example 2: Background Image with No Repeat
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Background Image Example</title> <style> body { background-image: url('your-image.jpg'); background-repeat: no-repeat; background-position: center; background-size: cover; } </style> </head> <body> <h1>This page has a background image.</h1> </body> </html>
background-color: Sets the background to a specific color (e.g., light blue in Example 1).
background-image: Adds an image as the background.
background-repeat: Prevents the image from repeating (default is to repeat).
background-position: Centers the background image.
background-size: Stretches the image to cover the entire background area.
Note: You can mix and match these properties for more complex background effects.
Popular post
-
Eclipse IDE – Create New Java Project.
Opening the New Java Project…
-
How to start the project in android studio
Android Studio Open the Android…
-
How to use ACOSH function in excel
The ACOSH function returns the…
-
Complete Header tags in html – easy to learn
H tags can be used…
-
Best features in Python programme – easy to learn
Python is the most widely…