
更改 css 中元素的背景颜色非常简单明了。步骤是:
选择元素:决定要更改其背景颜色的 html 元素。
使用背景颜色:在 css 文件中或 html 中的 <style> 标签中应用背景颜色属性。
例子
超文本标记语言
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="container">
<p id="paragraph">this is a paragraph.</p>
<button>click me</button>
</div>
</body>
</html>
css
/* Change background color of the body */
body {
background-color: lightblue;
}
/* Change background color of an element with the class 'container' */
.container {
background-color: lightgreen;
}
/* Change background color of an element with the id 'paragraph' */
#paragraph {
background-color: lightyellow;
}
/* Change background color of all button elements */
button {
background-color: lightcoral;
}










