HTML 将文本置于中心位置



我有这个常规的文本代码,它基本上只显示一个代码。但我想让艺术家留在中间,我该怎么做?

<div class="content">
<b><p style="font-size:18px;line-
height:10px;color:black;">SONGNAME</b> <br /></div>
<p style="font-size:18px; color:#FF2C55; line-height:0;">ARTIST<br/>
</div>

我试过位置:固定; 左:50% 它不起作用。我知道有很多关于这方面的例子,但我找不到与我的类似的代码。

在 ARTIST 元素中添加文本对齐:中心。

<p style="font-size:18px; color:#FF2C55; line-height:0; text-align: center;">ARTIST</p>

您还缺少 SONGNAME 元素上的结束标记。 你也可以取消你的 br 标签,因为div 本质上是块元素。

将艺术家的文本居中对齐。您的 html 也存在一些标记问题。

#artist{
text-align: center;
}
<html>
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body>
<div class="content">
<b><p style="font-size:18px;line-
height:10px;color:black;">SONGNAME</b> <br /></div>
<div id = 'artist'>
<p style="font-size:18px; color:#FF2C55; line-height:0;">ARTIST<br/>    
</p>
</div>
</body>
</html>

将"text-align:center;"添加到包含要居中的文本的元素的 style 属性中。 示例:

<html>
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body>
<div class="content">
<b><p style="font-size:18px;line-
height:10px;color:black;">SONGNAME</b> <br /></div>
<p style="font-size:18px; color:#FF2C55; line-height:0; text-align:center;">ARTIST<br/>    
</div>
</body>
</html>

相关内容

最新更新