What is the meaning of class in HTML? Introduction to the Class attribute usage of HTML (with instance)

Source: Internet
Author: User
This article mainly introduces the meaning of class in HTML and the usage instance parsing of class in HTML. The left post also has the function explanation of HTML class. Let's take a look at this article next.

First, let's introduce the meaning of class in HTML:

The class attribute specifies the name of the element (classname).

The class attribute is used most of the time to point to classes in a style sheet (class). However, it can also be used to change the HTML element with the specified class by using JavaScript.

The class= in HTML is a selector that can be understood as an identity that identifies a particular label.

For example: <divclass= "Div1" ></div> This is a logo effect, and later you want to change the style of this div, you can find the class is DIV1 elements.

In addition, the general Flash file is not seen, it just called. When you want to watch alone or directly download the Flash file, you can copy the name of the flash in the path to the browser can be directly read.

Note: The class attribute cannot be used in the following HTML elements: base, head, HTML, meta, param, script, style, and title.

Tip: You can assign multiple classes to HTML elements, for example: <span class= "Left_menu important" >. Doing so can combine several CSS classes into an HTML element.

Hint: The class name cannot begin with a number! Only Internet Explorer supports this practice.

Attribute values for the class attribute in HTML:

ClassName: The name of the class that specifies the element. To specify more than one class for an element, separate the class name with a space.

Now let's look at the use of the class attribute in HTML:

Here's an example of the class attribute in HTML: Using the class attribute in an HTML document:


Effects such as:

We can see this picture has changed the word, just a P tag text has not been effective, because the effect has not been set.

Class is a selector just like the ID, which, by defining the style, is called by the HTML tag to make the page typeset, laid out, and styled.

Here's an example of an HTML class:

<style> #nav {float:left;} /*id calls */.text{font-size:30px;}. text2{font-size:10px;} /*class call */</style><body>    <div id= "nav" >        <p class= "text" > First line of text topic.alibabacloud.com</p>        <p class= "Text2" >topic.alibabacloud.com second text </p>    < /div><body>

This effect is obvious, such as:

A font of 30 pixels, a mere 10 pixels, is not very obvious. This is the layout of the class selector's defined style.

The role of class in HTML is explained by:

Class is generally used for unified styling, for example, a UL inside all Li, his font, background color ah and so on, you can take all Li's class name to the same, because in the HTML class name these two names can be repeated, and then said that after you unified style, For example, a few Li's style is different, this time you give a few different styles of Li to take an ID, and then through the ID control his properties

Well, the above is the explanation of the HTML class, and the use of HTML class example also has a role to explain, there are questions can be asked below.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.