在HTML元素上分配多个样式

时间:2015-07-03 09:14:51

标签: html html5

我刚刚开始使用HTML,而且我在为文本分配多种样式时遇到了麻烦。 我想创建一个包含两个属性的标题:

  1. 居中
  2. 字体:Tahoma
  3. 我试过这个:

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

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

    我做错了什么?

4 个答案:

答案 0 :(得分:23)

米奇。在HTML中,样式标记具有以下语法:

style="property1:value1;property2:value2"

所以在你的情况下:

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

希望这有帮助。

答案 1 :(得分:4)

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

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

答案 2 :(得分:2)

你需要这样做:

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

希望对您有所帮助。

答案 3 :(得分:0)

您使用HTML语法的方式有问题。

这应该是语法

style="property1:value1;property2:value2"

您的情况就是这样

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

另一个例子如下

<div class ="row">
    <button type="button" style= "margin-top : 20px; border-radius: 15px" 
    class="btn btn-primary">View Full Profile</button>
</div>