-
-
Notifications
You must be signed in to change notification settings - Fork 156
Create Colors-and-Backgrounds.md #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
# Colors and Background | ||
|
||
In CSS, controlling colors and background properties is fundamental for styling web pages. This includes setting text colors, background colors, images, gradients, and more. Below are the main properties and techniques for handling colors and backgrounds in CSS. | ||
|
||
**1. Text Color** | ||
|
||
The color property sets the color of the text. Colors can be defined using various formats, such as named colors, HEX codes, RGB, RGBA, HSL, and HSLA. | ||
|
||
Hex - Codes : | ||
|
||
 | ||
|
||
RGB (Red-Green-Blue): | ||
|
||
<img src="https://tse4.mm.bing.net/th?id=OIP.zBlyNAyf8fFyqp7_vdv2mgHaCx&pid=Api&P=0&h=180" alt="RGB" height="500" width="400"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove height, width or maintain size of |
||
|
||
HSL (Hue-Saturation-Lightness): | ||
|
||
<img src="https://giggster.com/guide/static/fed42130c194b0c240a4ec10408adf97/8282f/hsl-cover-2.png" alt="HSL" height="200" width="200"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change size of |
||
|
||
```css | ||
/* Named color */ | ||
p { | ||
color: red; | ||
} | ||
|
||
/* HEX code */ | ||
h1 { | ||
color: #ff5733; | ||
} | ||
|
||
/* RGB */ | ||
div { | ||
color: rgb(255, 87, 51); | ||
} | ||
|
||
/* RGBA (with opacity) */ | ||
span { | ||
color: rgba(255, 87, 51, 0.8); | ||
} | ||
|
||
/* HSL */ | ||
a { | ||
color: hsl(11, 100%, 60%); | ||
} | ||
|
||
/* HSLA (with opacity) */ | ||
footer { | ||
color: hsla(11, 100%, 60%, 0.8); | ||
} | ||
``` | ||
|
||
**2. Background Color** | ||
|
||
The `background-color` property sets the background color of an element. | ||
|
||
```css | ||
/* Named color */ | ||
body { | ||
background-color: lightblue; | ||
} | ||
|
||
/* HEX code */ | ||
header { | ||
background-color: #333333; | ||
} | ||
|
||
/* RGB */ | ||
section { | ||
background-color: rgb(240, 240, 240); | ||
} | ||
|
||
/* RGBA (with opacity) */ | ||
nav { | ||
background-color: rgba(0, 0, 0, 0.5); | ||
} | ||
|
||
/* HSL */ | ||
article { | ||
background-color: hsl(210, 100%, 95%); | ||
} | ||
|
||
/* HSLA (with opacity) */ | ||
aside { | ||
background-color: hsla(210, 100%, 95%, 0.8); | ||
} | ||
``` | ||
|
||
**3. Background Image** | ||
|
||
The `background-image` property sets an image as the background of an element. You can also control its position, size, repeat behavior, and more. | ||
|
||
```css | ||
/* Background image */ | ||
body { | ||
background-image: url('path/to/image.jpg'); | ||
background-repeat: no-repeat; /* Prevents image from repeating */ | ||
background-size: cover; /* Scales image to cover the entire element */ | ||
background-position: center; /* Centers the image */ | ||
} | ||
|
||
/* Gradient background */ | ||
div { | ||
background-image: linear-gradient(to right, red, yellow); | ||
} | ||
``` | ||
|
||
**4. Background Repeat** | ||
|
||
The `background-repeat` property controls if/how a background image repeats. | ||
|
||
```css | ||
div { | ||
background-image: url('path/to/image.jpg'); | ||
background-repeat: no-repeat; /* Do not repeat the image */ | ||
background-repeat: repeat-x; /* Repeat the image horizontally */ | ||
background-repeat: repeat-y; /* Repeat the image vertically */ | ||
background-repeat: round; /* Repeat the image, but rescale to fit */ | ||
background-repeat: space; /* Repeat the image, but add space between repetitions */ | ||
} | ||
``` | ||
|
||
**5. Background Size** | ||
|
||
The `background-size` property specifies the size of the background image. | ||
|
||
```css | ||
section { | ||
background-image: url('path/to/image.jpg'); | ||
background-size: auto; /* Default, original size */ | ||
background-size: cover; /* Scale the image to cover the element */ | ||
background-size: contain; /* Scale the image to be contained within the element */ | ||
background-size: 100px 200px; /* Specify exact size */ | ||
background-size: 50% 50%; /* Specify size as a percentage */ | ||
} | ||
``` | ||
|
||
**6. Background Position** | ||
|
||
The `background-position` property sets the starting position of the background image. | ||
|
||
```css | ||
header { | ||
background-image: url('path/to/image.jpg'); | ||
background-position: left top; /* Align image to top left */ | ||
background-position: center; /* Center the image */ | ||
background-position: 50% 50%; /* Center the image using percentages */ | ||
background-position: 10px 20px; /* Set position using exact values */ | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change size of
img