简体   繁体   English

如何用 html 和 css 上色

[英]how to put color with html and css

I'm using html and css to create a site.我正在使用 html 和 css 创建站点。 the problem I am encountering is that I tyed the code to modify the color of some part in my text but when I open the doc in the browser the code does not have effect on the text.我遇到的问题是我绑定了代码来修改文本中某些部分的颜色,但是当我在浏览器中打开文档时,代码对文本没有影响。 Can someone please check what I'm doing wrong?有人可以检查我做错了什么吗?

 <p> <strong> <span class="titreengras">Company description </span> </strong> <br> Production description or service description ( we have both in the case of this business) In this section you talk about the offerings that you will establish for the people. what you will have available for your customers. Meaning you have to describe the product ( the hub...what it means...how it comes..it locations...its quality) and then the service ( establishment of cloud-based offices inter-related...certificationsand patents) </br> </p>

Well, you need to create a class in the style tag of your html page, like that snippet in the example.好吧,您需要在 html 页面的样式标签中创建一个 class ,就像示例中的片段一样。

 .titreengras { color: red; }
 <p> <strong> <span class="titreengras">Company description </span> </strong> <br> Production description or service description ( we have both in the case of this business) In this section you talk about the offerings that you will establish for the people. what you will have available for your customers. Meaning you have to describe the product ( the hub...what it means...how it comes..it locations...its quality) and then the service ( establishment of cloud-based offices inter-related...certifications and patents) <p/>

If you want to know more and study some stuff the https://www.w3schools.com/ is a nice start.如果您想了解更多并研究一些东西https://www.w3schools.com/是一个不错的开始。

To get it to work you will need three things:要让它工作,你需要三件事:

  1. Give a class to your html tag.为您的 html 标签提供 class。
<span class="titreengras">Company description </span>
  1. Create a css file with your styling.使用您的样式创建css文件。 Ex.: styles.css例如: styles.css
.titreengras {
    color: #41b230; // sets the color to any given hex value.
}
  1. You need to import your css file into the html file you were working on before.您需要将 css 文件导入您之前正在处理的 html 文件中。 Do it by linking your stylesheet inside the header of your html file.通过将样式表链接到 html 文件的 header 中来实现。 It should look something like this:它应该看起来像这样:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>File title</title>

    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body>

<!--- rest of the html file... -->

Where <link rel="stylesheet" type="text/css" href="style.css" /> is the line you need to insert on your head and style.css is the path for your css file.其中<link rel="stylesheet" type="text/css" href="style.css" />是您需要在头上插入的行,而style.css是 css 文件的路径。

You probably forgot to add your.css file between your header tag in index.html but here is the fixed snippet您可能忘记在 index.html 的 header 标记之间添加 your.css 文件,但这里是固定片段

 <style>.titreengras{ color: green;} </style> <p> <strong> <span class="titreengras">Company description </span> </strong> <br> Production description or service description ( we have both in the case of this business) In this section you talk about the offerings that you will establish for the people. what you will have available for your customers. Meaning you have to describe the product ( the hub...what it means...how it comes..it locations...its quality) and then the service ( establishment of cloud-based offices inter-related...certificationsand patents) </br> </p>

You can add styles directly by add style='color: yellow' in particular tag or add styles in CSS style sheet.您可以通过添加 style='color: yellow' 直接添加 styles 特别标签或在 CSS 样式表中添加 styles。 Make sure your CSS style sheet is linked properly by placing link rel="stylesheet" type="text/css" href="css/style.css" in Html file.通过在 Html 文件中放置链接 rel="stylesheet" type="text/css" href="css/style.css" 确保您的 CSS 样式表正确链接。

If styles still not working, clean browsing data.如果 styles 仍然无法正常工作,请清理浏览数据。

 <p>
   <strong>
    <span class='myClass' style='color: yellow'>Company description </span>
   </strong><br> Production description or service description ( we have both 
 in the case of this business) In this section you talk about the offerings 
 that you will establish for the people
 . what you will have available for your customers. Meaning you have to 
 describe the product ( the hub ...what it means ...how it comes ..it 
 locations ...its quality) and then the service ( establishment of cloud- 
 based offices inter-related...certifications
  and patents)
 </p>

  CSS FILE:
    myClass{
     color: yellow;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM