如何为HTML容器分配多个类?

本文翻译自:How to assign multiple classes to an HTML container?

Is it possible to assign multiple classes to a single HTML container? 是否可以将多个类分配给单个HTML容器?

Something like: 就像是:

<article class="column, wrapper"> 

#1楼

参考:https://stackoom.com/question/ab23/如何为HTML容器分配多个类


#2楼

To assign multiple classes to 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, column and wrapper are two separate css classes, and both of their properties will be applied to the article element. 在上面的示例中, columnwrapper是两个单独的css类,它们的两个属性都将应用于article元素。


#3楼

Yeah, no comma. 是的,没有逗号。 Just a space. 只是一个空间。 Because it thinks the comma is part of the first class, column. 因为它认为逗号是第一类,列的一部分。 Then it makes the class column, which doesn't work. 然后它生成类column,它不起作用。 Working code looks just like this: <article class="column wrapper"> 工作代码如下所示: <article class="column wrapper">


#4楼

只需删除这样的逗号:

<article class="column wrapper"> 

#5楼

From the standard 从标准

7.5.2 Element identifiers: the id and class attributes 7.5.2元素标识符:id和class属性

Attribute definitions 属性定义

id = name [CS] id = name [CS]
This attribute assigns a name to an element. 此属性为元素指定名称。 This name must be unique in a document. 该名称在文档中必须是唯一的。

class = cdata-list [CS] 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. 多个类名必须用空格字符分隔。

Yes, just put a space between them. 是的,只是在它们之间留一个空格。

<article class="column wrapper">

Of course, there are many things you can do with CSS inheritance. 当然,CSS继承可以做很多事情。 Here is an article for further reading . 这是一篇供进一步阅读文章

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值