更改 css 中元素的背景颜色非常简单明了。步骤是:
选择元素:决定要更改其背景颜色的 html 元素。
使用背景颜色:在 css 文件中或 html 中的
<link rel="stylesheet" type="text/css" href="styles.css"><div class="container"> <p id="paragraph">this is a paragraph.</p> <button>click me</button> </div>
/* 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; }