Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> CSS

การตั้งค่าตำแหน่งพื้นหลังใน CSS


คุณสมบัติ CSS ตำแหน่งพื้นหลังใช้เพื่อกำหนดตำแหน่งเริ่มต้นสำหรับรูปภาพพื้นหลังที่สัมพันธ์กับที่มา

ไวยากรณ์

ไวยากรณ์ของคุณสมบัติตำแหน่งพื้นหลัง CSS มีดังต่อไปนี้ -

Selector {
   background-position: /*value*/
}

ตัวอย่างต่อไปนี้แสดงให้เห็นถึงคุณสมบัติ CSS พื้นหลังตำแหน่ง -

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
<style>
div {
   margin: 30px;
   padding: 100px;
   background-image: url("https://www.tutorialspoint.com/images/C-programming.png"), url("https://www.tutorialspoint.com/images/Swift.png"), url("https://www.tutorialspoint.com/images/xamarian.png");
   background-repeat: no-repeat;
   background-position: 15% 20%, top, right;
   border: 1px solid;
}
</style>
</head>
<body>
<div>
</div>
</body>
</html>

ผลลัพธ์

สิ่งนี้ให้ผลลัพธ์ต่อไปนี้ -

การตั้งค่าตำแหน่งพื้นหลังใน CSS

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
<style>
p {
   margin: 20px;
   padding: 80px;
   background-image: url("https://www.tutorialspoint.com/images/dbms.png"), url("https://www.tutorialspoint.com/images/Operating-System.png");
   background-repeat: no-repeat;
   background-position: 0 0, bottom right;
   background-color: lemonchiffon;
}
</style>
</head>
<body>
<p>This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. This is demo paragraph. </p>
</body>
</html>

ผลลัพธ์

สิ่งนี้ให้ผลลัพธ์ต่อไปนี้ -

การตั้งค่าตำแหน่งพื้นหลังใน CSS