色彩中心

问题描述 投票:0回答:1

你好,我需要知道如何居中并用两种颜色构成一个句子。

<html>
<head>
<title>Website</title>
</head>
<body>
<div style="width: 400px; 
height: 400px; bgcolor: 
rgb(121,200,78); color: 
#,#,#;">
<p>Hello World</p>
</div>
</body>
</html>
html css colors rgb
1个回答
0
投票

您将需要稍微拆分一下代码。首先,使其居中,添加以下内容:text-align: center;。这将使您的内容在400像素宽度内居中。要使文本在页面上居中,请将宽度更改为100%。

对于颜色,如果您表示背景和文本颜色不同,则只需将color: #,#,#;更改为十六进制或rgb(link)。要使背景色起作用,请确保使用background-colorbackground代替“ bgcolor”。您的HTML将如下所示:

<html>
<head>
<title>Website</title>
</head>
<body>
  <div style="width: 400px; height: 400px; background-color: rgb(121,200,78); color: #COLOR">
  <p>Hello World</p>
  </div>
</body>
</html>

[另一方面,如果您要使用不同颜色的单词,那么要添加第二种颜色,我建议使用具有所需样式的span。完整的HTML就像这样:

<html>
<head>
<title>Website</title>
</head>
<body>
  <div style="width: 400px; height: 400px; background-color: rgb(121,200,78); color: #COLOR1">
  <p>Hello <span style="color: #COLOR2">World</span></p>
  </div>
</body>
</html>

我建议您深入研究我共享的W3 SChools链接,并查看一些HTML和CSS教程,一段简短的视频或阅读将有很大帮助。祝您学习顺利!

© www.soinside.com 2019 - 2024. All rights reserved.