This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
refactor(css): refactor background css topic based on guideline #77
Open
chrisdionisius
wants to merge
2
commits into
wrideveloper:master
Choose a base branch
from
chrisdionisius:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
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 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 |
---|---|---|
@@ -1,32 +1,54 @@ | ||
# Background | ||
|
||
Dengan menggunakan CSS, kita dapat memberikan background pada elemen HTML seperti div | ||
Dengan menggunakan CSS, kita dapat memberikan background pada elemen HTML seperti div. Terdapat beberapa jenis property untuk mengganti background sebuah elemen yakni : | ||
1. Background Color | ||
2. Background Image | ||
3. Background Repeat | ||
4. Background Position | ||
5. Background Attachment | ||
|
||
## 1. Background Color | ||
|
||
Kita bisa merubah warna background suatu elemen menggunakan property `background-color` | ||
|
||
```css | ||
body { | ||
background-color: lightblue; | ||
background-color: lightblue; /*menambahkan background berwarna biru muda pada elemen body*/ | ||
} | ||
h1 { | ||
background-color: green; | ||
background-color: #00FF00; /*menambahkan background berwarna hijau pada elemen h1 dengan hex value*/ | ||
} | ||
|
||
div { | ||
background-color: lightblue; | ||
background-color: rgb(0,0,255); /*menambahkan background berwarna biru pada elemen div menggunakan rgb value*/ | ||
} | ||
|
||
p { | ||
background-color: yellow; | ||
background-color: hsl(0, 87%, 81%); /*menambahkan background berwarna pink pada elemen p menggunakan hsl value*/ | ||
} | ||
``` | ||
## Opacity | ||
Kita juga dapat memberikan efek transparan pada sebuah background elemen dengan property `opacity` | ||
Comment on lines
+30
to
+31
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. opacity ini kyknya ga perlu, soalnya dia gak termasuk background, ntar bisa dimasukin ke materi lain 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. Baik mas, |
||
|
||
```css | ||
div { | ||
background-color: lightblue; | ||
opacity:0.4; | ||
} | ||
``` | ||
*note : penggunaan property opacity juga berdampak pada semua child element dari suatu elemen yang memiliki property opacity, sehingga bisa jadi konten dalam element tersebut juga terkena efek tranparan, untuk mengatasi ini kita bisa menggunakan rgba value. | ||
|
||
```css | ||
div { | ||
background-color: rgba(76, 175, 80, 0.3); /* menambahkan warna hijau dengan 30% efek transparan pada div */ | ||
} | ||
``` | ||
|
||
|
||
|
||
## 2. Background Image | ||
|
||
Kita juga bisa merubah background menggunakan image tertentu, caranya dengan menggunakan property `background-image` | ||
|
||
```css | ||
body { | ||
background-image: url('bgdesert.jpg'); | ||
|
@@ -35,7 +57,8 @@ body { | |
|
||
## 3. Background Repeat | ||
|
||
Apabila image yang kita jadikan background tidak cukup besar, maka kita bisa melakukan repeating pada image tersebut menggunakan property `background-repeat` | ||
Apabila image yang kita jadikan background tidak cukup besar, maka kita bisa melakukan repeating pada image tersebut menggunakan property `background-repeat`. | ||
Namun secara default jika kita memiliki sebuah gambar yang lebih kecil dari ukuran elemen yang dipasangi background maka gambar akan secara otomatis melakukan repeat baik secara vertikal maupun horizontal sampai background elemen tercover seluruhnya | ||
|
||
```css | ||
/* repeat secara horizontal */ | ||
|
@@ -59,7 +82,7 @@ h1 { | |
|
||
## 4. Background Position | ||
|
||
Apabila image yang kita jadikan background terlalu besar, kita dapat memposisikan background tersebut menggunakan property `background-position` dan diisi dengan posisi horizontal dan vertical | ||
Property background position digunakan untuk mengatur posisi gambar yang digunakan untuk background elemen. Untuk mengaturnya kita dapat menggunakan property `background-position` diikuti dengan value horizontal align dan vertical align. | ||
|
||
```css | ||
/* posisikan background secara horizontal center dan vertical center */ | ||
|
@@ -73,4 +96,30 @@ div { | |
background-image: url('background.jpg'); | ||
background-position: left top; | ||
} | ||
|
||
/* penggunaan background-position diikuti dengan property background-repeat jika gambar terlalu kecil */ | ||
body { | ||
background-image: url("img_tree.png"); | ||
background-repeat: no-repeat; | ||
background-position: right top; | ||
} | ||
|
||
``` | ||
|
||
## 5. Background Attachment | ||
Property ini dapat digunakan untuk mengatur apakah posisi background fixed atau tidak (jika di scroll ikut background ikut turun mengikuti laman). | ||
```css | ||
/* posisikan background fixed */ | ||
body { | ||
background-image: url("img_tree.png"); | ||
background-attachment: fixed; | ||
} | ||
|
||
/* posisikan background scroll */ | ||
body { | ||
background-image: url("img_tree.png"); | ||
background-attachment: scroll; | ||
} | ||
``` | ||
|
||
|
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.
ini langsung ke materi ya, tambahin permalasahan dong, kenapa kita butuh nentuin background di web.
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.
Nggih mas, segera saya kerjakan