使用 CSS 的红绿蓝模型 (RGB) 定义颜色
在网站设计中,颜色至关重要。它会影响用户点击的链接、他们阅读信息的方式以及他们在浏览您的网站时的舒适度。在整合颜色时需要练习,而当您使用 CSS 的 color 和 background-color 属性时,将其添加到您的网站非常简单。
这些属性可以通过多种方式定义。可以使用 HTML 颜色名称、十六进制颜色代码、RGB 颜色代码或 HSL 颜色值来更改网页的文本或背景颜色。在本文中,我们将学习有关 RGB 颜色的知识。
RGB(红绿蓝)
可以通过定义 R、G 和 B 值范围从 0 到 255,使用RGB(红、绿、蓝)格式来定义 HTML 元素的颜色。例如,黑色(0、0、0)、白色(255、255、255)、黄色(255、255、0)等的颜色 RGB 值。
语法
以下是 RGB 颜色格式的语法:
rgb(red, green, blue)
示例
让我们看一下以下示例,我们将使用 RGB 颜色
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: verdana;
text-align: center;
background-color: rgb(213, 245, 227);
}
h1 {
color: rgba(142, 68, 173);
}
P {
color: rgb(222, 49, 99);
}
</style>
</head>
<body>
<h1> TUTORIALSPOINT </h1>
<P>Tutorials Point originated from the idea that there exists a class of readers who respond better to online content and prefer to learn new skills at their own pace from the comforts of their drawing rooms.</P>
</body>undefined
</html>
当我们运行以上代码时,它将生成一个输出,其中包含应用了 CSS 的文本显示在网页上。
示例
考虑另一种情况,我们将看到 RGB 颜色的用法。
<!DOCTYPE html>
<html>
<head>
<style>
.tp {
position: absolute;
inset: 0;
margin: auto;
width: 200px;
height: 200px;
border-radius: 10px;
transform: rotate(69deg);
}
div {
height: 250px;
margin-top: 250px;
background: rgb(249, 231, 159);
}
.tp {
background: rgb(30 132 73/0.8);
}
</style>
</head>
<body>
<div>
<div class="tp"></div>
</div>
</body>
</html>
运行以上代码后,输出窗口将弹出,在网页上显示应用了 CSS 的 div 框
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP