使用 CSS 设置背景位置

cssweb developmentfront end technology更新于 2024/12/10 10:52:17

背景位置用于设置背景图像的起始位置。为此,请使用 background-position 属性。

示例

现在让我们看一个例子 −

<!DOCTYPE html>
<html>
<head>
<style>
body {
   background-image: url("https://www.cainiaomax.com/images/Swift.png");
   background-repeat: no-repeat;
   background-attachment: fixed;
   color: blue;
   background-position: left center;
}
.demo {
   text-decoration: overline underline;
}
</style>
</head>
<body>
<h1>Details</h1>
<p class="demo">Examination Center near ABC College.</p>
<p class="demo2">Exam begins at 9AM.</p>
</body>
</html>

输出

示例

现在让我们看另一个例子 −

<!DOCTYPE html>
<html>
<head>
<style>
body {
   background-image: url("https://www.cainiaomax.com/images/Swift.png");
   background-repeat: no-repeat;
   background-attachment: fixed;
   color: blue;
   background-position: 50% 50%;
}
</style>
</head>
<body>
<h1>Details</h1>
<p>Examination Center near ABC College.</p>
<p>Exam begins at 9AM.</p>
</body>
</html>

输出


相关文章


有用资源