在 HTML 元素上分配多种样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31202996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:44:27  来源:igfitidea点击:

Assigning multiple styles on an HTML element

html

提问by Mickey

I'm just starting out with HTML and I'm having a trouble assigning multiple styles to a text. I'd like to create a title with two properties:

我刚开始使用 HTML,在为文本分配多种样式时遇到了问题。我想创建一个具有两个属性的标题:

  1. Centered
  2. Font: Tahoma
  1. 居中
  2. 字体:Tahoma

I have tried this one:

我试过这个:

<h2 style="text-align:center";"font-family:tahoma">TITLE</h2>

but it doesn't work...

但它不起作用......

What am I doing wrong?

我究竟做错了什么?

回答by Bazindrix

In HTML the style tag has the following syntax:

在 HTML 中,样式标签具有以下语法:

style="property1:value1;property2:value2"

so in your case:

所以在你的情况下:

<h2 style="text-align:center;font-family:tahoma">TITLE</h2>

Hope this helps.

希望这可以帮助。

回答by Antwane

The syntax you used is problematic. In html, an attribute (ex: style) has a value delimited by double quotes. In that case, the value of the style attribute is a css list of selectors. Try this:

您使用的语法有问题。在 html 中,属性(例如:样式)具有由双引号分隔的值。在这种情况下,style 属性的值是一个 css 选择器列表。尝试这个:

<h2 style="text-align:center; font-family:tahoma">TITLE</h2>