首頁 > web前端 > css教學 > 主體

更改 CSS 中的背景顏色

王林
發布: 2024-07-29 00:08:13
原創
319 人瀏覽過

Change background color in CSS

改變 CSS 中元素的背景顏色非常簡單明了。步驟是:

  1. 選擇元素:決定要變更其背景顏色的 HTML 元素。

  2. 使用背景顏色:在 CSS 檔案或

例子

超文本標記語言

<!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;
}

登入後複製

以上是更改 CSS 中的背景顏色的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:dev.to
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!