Bùi Tấn Lực
- 21
- 05/10/2025
Thuộc tính background-origin trong CSS dùng để quy định cách hiển thị của hình nền so với border-top, border-left, padding-top, padding-left, chi tiết như nào hãy cùng chúng tôi phân tích:
Thuộc tính background-origin trong CSS
Chức năng của Thuộc tính background-origin trong CSS
Thuộc tính background-origin trong CSS dùng để quy định cách hiển thị của hình nền so với border-top, border-left, padding-top, padding-left trên phần tử HTML.
Code Thuộc tính background-origin trong CSS
Các giá trị của thuộc tính background-origin trong CSS
<!DOCTYPE html>
<html>
<head>
<title>Các giá trị của thuộc tính background-origin trong CSS</title>
<style>
#padding-box {
background-image: url(https://webmoi.vn/thumuc/ceo-bui-tan-luc.jpg);
border: 10px dashed red;
padding: 25px;
background-repeat: no-repeat;
background-origin: padding-box;
color:red;
margin-bottom:15px;
}
#border-box {
background-image: url(https://webmoi.vn/thumuc/ceo-bui-tan-luc.jpg);
border: 10px dashed red;
padding: 25px;
background-repeat: no-repeat;
background-origin: border-box;
color:red;
margin-bottom:15px;
}
#content-box {
background-image: url(https://webmoi.vn/thumuc/ceo-bui-tan-luc.jpg);
border: 10px dashed red;
padding: 25px;
background-repeat: no-repeat;
background-origin: content-box;
color:red;
margin-bottom:15px;
}
</style>
</head>
<body>
<h1>Các giá trị của thuộc tính background-origin trong CSS</h1>
<div id="padding-box">
<p>background-origin: padding-box (background trong border-top và border-left)</p>
</div>
<div id="border-box">
<p>background-origin: border-box (background phủ tất cả border)</p>
</div>
<div id="content-box">
<p>background-origin: content-box (background trong border-top và border-left và trong padding-top và padding-left)</p>
</div>
</body>
</html>
Kết hợp các giá trị của thuộc tính background-origin trong CSS
<!DOCTYPE html>
<html>
<head>
<title>Kết hợp các giá trị của thuộc tính background-origin trong CSS</title>
<style>
#padding-box {
background-image: url(https://webmoi.vn/thumuc/bg-cay.png), url(https://webmoi.vn/thumuc/bg-nho.jpg);
border: 10px dashed red;
padding: 25px;
background-repeat: no-repeat;
background-origin: content-box, padding-box;
color:red;
margin-bottom:15px;
}
#border-box {
background-image: url(https://webmoi.vn/thumuc/bg-cay.png), url(https://webmoi.vn/thumuc/bg-nho.jpg);
border: 10px dashed red;
padding: 25px;
background-repeat: no-repeat;
background-origin: content-box, border-box;
color:red;
margin-bottom:15px;
}
#content-box {
background-image: url(https://webmoi.vn/thumuc/bg-cay.png), url(https://webmoi.vn/thumuc/bg-nho.jpg);
border: 10px dashed red;
padding: 25px;
background-repeat: no-repeat;
background-origin: content-box, content-box;
color:red;
margin-bottom:15px;
}
</style>
</head>
<body>
<h1>Kết hợp các giá trị của thuộc tính background-origin trong CSS</h1>
<div id="padding-box">
<p>background-origin: content-box, padding-box;</p>
</div>
<div id="border-box">
<p>background-origin: content-box, border-box;</p>
</div>
<div id="content-box">
<p>background-origin: content-box, content-box;</p>
</div>
</body>
</html>
Chạy Thử
Cảm ơn các bạn đã tham khảo bài viết Thuộc tính background-origin trong CSS.
- 0 Bình luận

Bùi Tấn Lực
CEO Bùi Tấn Lực người sáng lập ra Web Mới, là một lập trình viên website, người viết content, chuyên tư vấn các vấn đề về website và SEO website
Chia sẻ nội dung đánh giá của bạn về Thuộc tính background-origin trong CSS
Email, Điện thoại của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *
Email, Điện thoại của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *
Bình luận, Hỏi đáp
Đăng ký tư vấn miễn phí
Tìm hiểu 1 năm không bằng lắng nghe 1 câu tư vấn