在CSS中的同一元素上使用多个类和子类的最佳方法

时间:2016-01-04 07:15:47

标签: html css

如何为同一元素使用三个不同的类?两个人共享同一个父类是否重要?我有一个使用某些功能的字体链接,所以它有一个typeform类。但我也想把它.button.white和/或.button.transparent

我目前正在尝试这样的事情:

<a class="typeform-share button white button transparent">
<a class="typeform-share" class="button white" class="button transparent>

更新:我误解了css中的类是如何工作的。现在我发现了另一个问题 - 将创建一个新问题。谢谢大家!

1 个答案:

答案 0 :(得分:2)

这种html标记语法无效:

<a class="typeform-share" class="button white" class="button transparent">

您不能使用同名的多个属性。如果您使用浏览器将使用它第一个声明的即ie。以上将是:

<a class="typeform-share">

要使用多个类,只需使用与之前标记类似的空格分隔值。但是你并不需要多次同一个班级:

<a class="typeform-share button white button transparent">
<!--Remove one of the button class, you don't need to repeat-->

这里有来自CSS Tricks的how to work with multiple classes链接,可以让您的生活更轻松。