Assigning Multiple Styles on an Html Element

Assigning Multiple Styles on an Html Element

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:

  1. Centered
  2. Font: 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?

1

4 Answers

In HTML the style attribute has the following syntax:

style="property1:value1;property2:value2"

so in your case:

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

Hope this helps.

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 declarations. Try this:

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

The way you have used the HTML syntax is problematic.

This is how the syntax should be

style="property1:value1;property2:value2"

In your case, this will be the way to do

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

A further example would be as follows

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

I got stuck on the same issue and I hope this helps someone someday:


<style>
  .red-text {
    color: red;} p {font-size: 16px;}
</style>
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.