目录
如何在 HTML 中设置背景颜色?
首页 web前端 html教程 HTML 颜色 

HTML 颜色 

Sep 04, 2024 pm 04:33 PM
html html5 HTML Tutorial HTML Properties HTML tags

本文介绍了如何使用 HTML 以简单易行的方式在网站中使用颜色。颜色在创建网站的外观和感觉方面发挥着重要作用。 HTML 中没有单独的标签;相反,它使用样式属性或颜色属性。准确地说,颜色是使用层叠样式表 (CSS) 嵌入到 HTML 元素中的。颜色赋予网页优雅的外观。为网页添加颜色包括设置背景颜色、表格、段落等

如何在 HTML 中设置背景颜色?

使背景颜色变亮使网站看起来更漂亮、更大胆。它是通过使用颜色、十六进制颜色代码来完成的。 RGB 和 RGBA 颜色值(Alpha 值 0 到 1)。

使用 Html body 元素内的 Style 属性将十六进制颜色直接应用于 Html 代码。十六进制是数字和字母的组合。以下是网页背景颜色的示例。

代码:

<!DOCTYPE html>
<title>My Sample</title>
<html>
<head>
<title>HTML BG Color</title>
</head>
<body style="background-color:red;">
<h1> This page is a demo </h1>
</body>
</html>
登录后复制

代码片段:

HTML 颜色 

要添加背景颜色,可以使用 bgcolor 属性来显示

body bgcolor=''>.它与除 HTML 5 之外的所有浏览器兼容。

代码:

<h3 style="color: blue">Color Name</h3>
<h3 style="color: #0000ff">Hexadecimal</h3>
<h3 style="color: rgb (0,0,255)">RGB Value</h3>
登录后复制

如何为 HTML 中的文本应用颜色?

对 HTML 文本应用颜色非常简单;我们可以通过三种方式添加/更改文本的颜色,即十六进制颜色、HSL 值和颜色名称。以下是向相应网页应用颜色的三种不同技术。

1.颜色名称

当应用程序直接使用这些颜色名称时,使用英文颜色名称非常简单。指定颜色名称是直接方法,W3C已经公布了16种基本颜色(黑色、黄色、红色、栗色、灰色、石灰、绿色、橄榄色、银色、水色、蓝色、海军蓝、白色、紫色、紫红色、青色)

2.福胜利

色相饱和度和亮度颜色值。色调定义为 0 到 360 度,饱和度和亮度定义为 0 到 100 %。

3.十六进制颜色

为了获得精确的结果,使用六位十六进制数。详细来说,前两位表示红色,后两位表示绿色,另外两位表示蓝色值,前面带有‘#’。

以下示例说明了向文档应用颜色的不同方法。

代码:

<head>
<title>EDUCBA</title>
<style type="text/css">
h1{
color:#97cae0;
background-color: hsl(200, 50%, 20%);
color: hsl(200, 20%, 90%);
}
h4{
color:rgb(0, 255, 0);
background-color: hsl(130, 10%, 30%);
color: hsl(280, 20%, 80%);
}
li{
color:rgba(12, 88, 120, 1);
background-color: hsl(210, 36%, 50%);
color: hsl(145, 45%, 81%);
}
</style>
</head>
<body>
<h1>EDUCBA</h1>
<h4>List of operating System</h4>
<ul>
<li> Windows</li>
<li>MACINTOSH</li>
<li>LINUX</li>
<li>UBUNTU</li>
</ul>
</body>
</html>
登录后复制

输出:

HTML 颜色 

有不同的方法来设置文本颜色,因为 HTML 有很多可定制的应用程序。
  • 应用样式部分
  • 创建单独的 CSS 样式表
  • 换行文本

如何使用

The styles for Html documents

Each tag to be styled with colors.

输出:

HTML 颜色 

5.创建个人 CSS 样式

代码:

.html 文件:







  CSS style sheet

Multiple HTMl Document.

Hello world!

外部 CSS 文件 lcolor.css:

代码:

.lcolor { font-size: 40px;
color:red }

输出:

HTML 颜色 <🎜>

How to Set Border Color in HTML?

It is done using an attribute border color=” “. It is done using the Html element

and even we can create 3D effects. The border color is applied using different attributes like border= “width”, bordercolor= “color def”, bordercolorlight=” “. CSS has some enhanced border properties that help in creating borders. The below example shows setting a single border color to the corresponding table. Here denotes table row and
denotes table data and it is started using tag. And the border for them is applied using their width and colors

Code:




Chicago new york Texas California

Output:

HTML 颜色 

Now let’s see setting two border-color separately. The below code uses table attribute with their elements.

Code:




Samsung Nokia
Apple Iphone   Xiami Redmi

Output:

HTML 颜色 

Using

tag

It is used to group all the elements and helps in view of a web page at its particular position. In the below code, we have used two

one for a paragraph and the other to implement style attribute by setting border pixels and thickness is increased by giving out the width, and we have added padding to demonstrate them to the left.

Code:





 Sample border color using div


Nature is beautiful

div with a border color.

Output:

HTML 颜色 

Example: This explains how to set the color for padding and margin using class and list tags.

Code:




Borders



  • DOM model
  • Document object model helps in creating document tree

Output:

HTML 颜色 

How to Specify Color Using Values in HTML?

The basic color values vary from 0 to 255 for red, blue, green. The color value is important in giving out lightness.

The below table shows sample values for the colors.

HTML 颜色 

Example: The below example shows different color values in their background settings.

Code:




Data Mining techniques is to understand a patterns

Classification

Prediction

Regression

Classification, Prediction techniques

HTML colors

Table colors

Output:

HTML 颜色 

How to use RGB Color Values in HTML?

RGB denotes Red, Green blue colors directly and uses the RGB function. It takes those three values as parameters and declared them as integers sometimes in percentage. Whichever color we want, its intensity is given a higher value 255 as an integer value falls between o to 255. For instance, to have a blue color, it is preferred to denote (0,0,255). here the first two values are marked as 0,0, and the last value is 255 for blue.

Example: RGB color

Code:





Norway the most beautiful place it’s a Scandinavian Country.

It is the most expensive country in the world, Oslo is the capital of this green city.

Output:

HTML 颜色 

How to Specify the Lightness of Colors in HTML?

The lightness of color is defined by the brightness we prefer; it is measured in percentage. Most web designers wish to use lightness than RGB, which can be adjusted as per the requirements. Here a black set the brightness to 0% white set to 100%. It is specified using function hsl().

Code:





Norway the most beautiful place its an Scandinavian Country.

It is the most expensive country in the world, Oslo is the capital of this green city.

Output:

HTML 颜色 

You can try with different values for color in the above example.

Conclusion – HTML Colors

Therefore, to conclude, we have seen that this has different properties. In earlier days, web development has many ways to specify colors for their website, and nowadays, the most popular colorways are RGB and Hex color codes (RGB is well-known). There are different applications where colors are implemented, like a sliding scale, color palette, etc.

以上是HTML 颜色 的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1653
14
CakePHP 教程
1413
52
Laravel 教程
1304
25
PHP教程
1251
29
C# 教程
1224
24
HTML 中的表格边框 HTML 中的表格边框 Sep 04, 2024 pm 04:49 PM

HTML 表格边框指南。在这里,我们以 HTML 中的表格边框为例,讨论定义表格边框的多种方法。

HTML 中的嵌套表 HTML 中的嵌套表 Sep 04, 2024 pm 04:49 PM

这是 HTML 中嵌套表的指南。这里我们讨论如何在表中创建表以及相应的示例。

HTML 左边距 HTML 左边距 Sep 04, 2024 pm 04:48 PM

HTML 左边距指南。在这里,我们讨论 HTML margin-left 的简要概述及其示例及其代码实现。

HTML 表格布局 HTML 表格布局 Sep 04, 2024 pm 04:54 PM

HTML 表格布局指南。在这里,我们详细讨论 HTML 表格布局的值以及示例和输出。

HTML 输入占位符 HTML 输入占位符 Sep 04, 2024 pm 04:54 PM

HTML 输入占位符指南。在这里,我们讨论 HTML 输入占位符的示例以及代码和输出。

HTML 有序列表 HTML 有序列表 Sep 04, 2024 pm 04:43 PM

HTML 有序列表指南。在这里我们还分别讨论了 HTML 有序列表和类型的介绍以及它们的示例

HTML onclick 按钮 HTML onclick 按钮 Sep 04, 2024 pm 04:49 PM

HTML onclick 按钮指南。这里我们分别讨论它们的介绍、工作原理、示例以及各个事件中的onclick事件。

在 HTML 中移动文本 在 HTML 中移动文本 Sep 04, 2024 pm 04:45 PM

HTML 中的文本移动指南。在这里我们讨论一下marquee标签如何使用语法和实现示例。

See all articles