你好,我需要知道如何居中并用两种颜色构成一个句子。
<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>
您将需要稍微拆分一下代码。首先,使其居中,添加以下内容:text-align: center;
。这将使您的内容在400像素宽度内居中。要使文本在页面上居中,请将宽度更改为100%。
对于颜色,如果您表示背景和文本颜色不同,则只需将color: #,#,#;
更改为十六进制或rgb(link)。要使背景色起作用,请确保使用background-color
或background
代替“ 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教程,一段简短的视频或阅读将有很大帮助。祝您学习顺利!