Cơ sở dữ liệu - Bài 6: CSS Backgrounds

pptx 52 trang vanle 2040
Bạn đang xem 20 trang mẫu của tài liệu "Cơ sở dữ liệu - Bài 6: CSS Backgrounds", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên

Tài liệu đính kèm:

  • pptxco_so_du_lieu_bai_6_css_backgrounds.pptx

Nội dung text: Cơ sở dữ liệu - Bài 6: CSS Backgrounds

  1. Bài 6: CSS Backgrounds BỞI TRỊNH HỒNG
  2. • Thuộc tính Background trong CSS dùng để định nghĩa background (hình nền) cho các phần tử • Các thuộc tính Background trong CSS bao gồm: • background-color • background-image • background-repeat • background-attachment • background-position
  3. • Background Color • Thuộc tính background-color xác định màu nền cho các phần tử • Background Color của một trang được xác định theo cấu trúc sau:
  4. • Ví dụ 1: • body { background-color: lightblue; }
  5. • Trong CSS, có nhiều cách định kiểu màu, thường được sử dụng theo các cách sau: • Theo tên tiếng anh – ví dụ: “Red”- màu đỏ • Theo kết hợp giá trị màu RGB – ví dụ: “rgb(255, 0, 0)”- màu đỏ • Theo hệ thập lục phân HEX – ví dụ: “#ff0000” – màu đỏ
  6. Trong ví dụ dưới đây, thẻ , và sẽ có background color khác nhau:
  7. • Background Image • Thuộc tính background-image xác định một hình ảnh làm background cho một phần tử. • Mặc định thì hình ảnh sẽ được lặp lại vì thế nó bao phủ toàn bộ phần tử. • Background image của một trang được xác định theo cấu trúc sau:
  8. • CSS: body { background-image: url("//timoday.edu.vn/wp- content/uploads/2017/06/hinh-nen- powerpoint-don-gian-dep-30-461x346.jpg"); }
  9. Lưu ý: khi sử dụng hình ảnh làm background, thì bạn nên sử dụng hình ảnh mà nó không gây ảnh hưởng lên các văn bản. Nếu không ảnh đó sẽ đè hoặc làm mờ chữ hoặc nội dung trang web của bạn.
  10. • Ví dụ 4: • body { background-image: url(“bgdesert.jpg”); }
  11. • Background Image – Lặp lại ảnh theo chiều dọc hoặc ngang • Mặc định thì thuộc tính background-image sẽ lặp ảnh cả 2 dạng dọc và ngang (horizontally và vertically). • Một số ảnh nên được lặp ngang hoặc dọc, nếu không thì trông nó rất là xấu, không đẹp mắt, giống như sau:
  12. • Ví dụ 5: • body { background-image: url(“gradient_bg.png”); }
  13. • CSS: body { background-image: url(" content/uploads/2017/06/images1234.jpg"); }
  14. Nếu như ảnh trên chỉ được lặp lại theo chiều ngang (background-repeat: repeat-x;), thì sẽ trông tốt hơn:
  15. • Ví dụ 6: • body { background-image: url(“gradient_bg.png”); background-repeat: repeat-x; }
  16. • CSS: body { background-image: url(" content/uploads/2017/06/Green-White-Striped- Wallpaper-New-wide-stripe-wallpaper- 157912.jpg"); background-repeat: repeat-x; }
  17. Lưu ý: Để lặp lại một image theo chiều dọc (vertically), chúng ta set background-repeat: repeat-y;
  18. • Background Image – Thiết lập vị trí và không lặp • Để hiển thị hình nền chỉ một lần cũng được xác định bởi thuộc tính background- repeat:
  19. • Ví dụ 7: • body { background-image: url(“img_tree.png”); background-repeat: no-repeat; }
  20. • CSS: body { background: #ffffff url(" content/uploads/2017/06/imagesabc.jpg"); background-repeat: no-repeat;
  21. • Trong ví dụ trên background image hiển thị cùng nơi với text. Chúng ta muốn thay đổi vị trí của hình ảnh, để nó không che khuất text quá nhiều. • Vị trí của hình ảnh được xác định với thuộc tính background-position:
  22. • Ví dụ 8: • body { background-image: url(“img_tree.png”); background-repeat: no-repeat; background-position: right top; }
  23. • HTML: Hello World! W3Schools background no-repeat, set position example. Now the background image is only shown once, and positioned away from the text. In this example we have also added a margin on the right side, so the background image will never disturb the text.
  24. • CSS: body { background: #ffffff url(" content/uploads/2017/06/imagesabc.jpg"); background-repeat: no-repeat; background- position: right top; margin-right: 300px; }
  25. • Background Image – Cố định vị trí • Để chỉ định ảnh nền sẽ cố định (tức là nó sẽ không bị di chuyển mất khi cuộn), sử dụng thuộc tính background-attachment:
  26. • Ví dụ 9: • body { background-image: url(“img_tree.png”); background-repeat: no-repeat; background-position: right top; background-attachment: fixed; }
  27. HTML: Hello World! The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. The background-image is fixed. Try to scroll down the page. If you do not see any scrollbars, try to resize the browser window.
  28. • Thuộc tính background – Viết code ngắn • Để rút ngắn code, bạn có thể chỉ định tất cả các thuộc tính background trên cùng một dòng duy nhất. Nó được gọi là thuộc tính Shorthand. • Ví dụ 10: • body { background: #ffffff url(“img_tree.png”) no- repeat right top; }
  29. • HTML: Hello World! Now the background image is only shown once, and it is also positioned away from the text. In this example we have also added a margin on the right side, so that the background image will not disturb the text.
  30. • Khi sử dụng thuộc tính shorthand thì thứ tự giá trị thuộc tính sẽ là : • background-color • background-image • background-repeat • background-attachment • background-position • Nếu nhu cầu của bạn không cần sử dụng hết thuộc tính này trong shorthand thì không quan trọng, bạn chỉ việc không đưa nó vào miễn sao vẩn theo thứ tự như trên là được.
  31. • Tất cả các thuộc tính Background trong CSS