CSS 中的背景简写属性

cssweb developmentfront end technology更新于 2025/1/14 9:16:17

CSS 背景简写属性用于定义元素的背景。background-color、background-image、background-repeat、background-position、background-clip、background-size、background-origin 和 background-attachment 共同构成了 CSS 背景属性。

语法

CSS 背景属性的语法如下 −

Selector {
   background: /*value*/
}

示例

以下示例说明了 CSS 背景属性 −

<!DOCTYPE html>
<html>
<head>
<style>
body {
   background: linen url("https://www.cainiaomax.com/images/library-sub-banner.jpg") no-repeat 40% 20%;
}
div {
   padding: 100px;
   background: rgba(50,100,50,0.4)url("https://www.cainiaomax.com/green/images/logo.png") no-repeat left;
}
</style>
</head>
<body>
<h2>Learn</h2>
<ul>
<li>Java</li>
<li>C#</li>
<li>Android</li>
<li>iOS</li>
<li>C++</li>
<li>C</li>
</ul>
<div></div>
</body>
</html>

输出

这将给出以下输出 −

示例

<!DOCTYPE html>
<html>
<head>
<style>
table, tr,td{
   margin: auto;
   border: 2px solid red;
   padding: 40px;
}
td {
   background: rgba(50,100,50,0.4)url("https://www.cainiaomax.com/images/blockchain.png") no-repeat;
}
#demo {
   background: rgba(50,100,50,0.4)url("https://www.cainiaomax.com/images/reactjs.png") no-repeat;
}
table {
   background: ivory url("https://www.cainiaomax.com/images/library-sub-banner.jpg") no-repeat center;
}
</style>
</head>
<body>
<h2>Learning is fun</h2>
<table>
<tr><td></td></tr>
<tr><td id="demo"></td></tr>
</table>
</body>
</html>

输出

这将给出以下输出 −


相关文章


有用资源