如何将多个类分配给一个 HTML 容器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8722163/
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 12:20:29  来源:igfitidea点击:

How to assign multiple classes to an HTML container?

htmlclass

提问by ARGO

Is it possible to assign multiple classes to a single HTMLcontainer?

是否可以将多个类分配给单个HTML容器?

Something like:

就像是:

<article class="column, wrapper"> 

回答by Aurelio De Rosa

Just remove the comma like this:

只需像这样删除逗号:

<article class="column wrapper"> 

回答by Jonathan Henson

From the standard

从标准

7.5.2 Element identifiers: the id and class attributes

Attribute definitions

id = name [CS]
This attribute assigns a name to an element. This name must be unique in a document.

class = cdata-list [CS]
This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or names. Multiple class names must be separated by white space characters.

7.5.2 元素标识符:id 和 class 属性

属性定义

id = name [CS]
此属性为元素分配名称。此名称在文档中必须是唯一的。

class = cdata-list [CS]
此属性为元素分配一个类名或一组类名。可以为任意数量的元素分配相同的类名。多个类名必须用空格字符分隔。

Yes, just put a space between them.

是的,只需在它们之间留一个空格。

<article class="column wrapper">

Of course, there are many things you can do with CSS inheritance. Here is an article for further reading.

当然,您可以使用 CSS 继承做很多事情。这里有一篇文章供进一步阅读

回答by Webeng

To assign multiple classesto an html element, include both class names within the quotations of the class attribute and have them separated by a space:

要将多个类分配给一个html 元素,请在 class 属性的引号内包含两个类名,并用空格分隔它们:

<article class="column wrapper"> 

In the above example, columnand wrapperare two separate css classes, and both of their properties will be applied to the articleelement.

在上面的例子中,columnwrapper是两个单独的 css 类,它们的两个属性都将应用于article元素。

回答by amit kumar

you need to put a dot between the class like

你需要在类之间放一个点,比如

class="column.wrapper">

class="column.wrapper">