HTML 颜色 

王林
发布: 2024-09-04 16:33:57
原创
380 人浏览过

本文介绍了如何使用 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中文网其他相关文章!

来源:php
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!