Html 使用不同类属性的同一元素的多个CSS类
我需要为HTML元素指定多个类属性。当我尝试使用以下代码段时,它只应用Html 使用不同类属性的同一元素的多个CSS类,html,css,Html,Css,我需要为HTML元素指定多个类属性。当我尝试使用以下代码段时,它只应用类a,而不应用类b <html> <head> <style> .a { color:Red; } .b { background-color: Green; } </style> </head> <body cl
类a
,而不应用类b
<html>
<head>
<style>
.a
{
color:Red;
}
.b
{
background-color: Green;
}
</style>
</head>
<body class="a" class="b"> Hello World </body>
</html>
当$attributes转换为class属性时,类“b”将被忽略。您需要找到一种方法将自定义的to类附加到服务器端变量。我假设$attributes将包含
类以外的许多属性,因此需要使用replace/regex样式的方法
如果使用php,可以尝试:
$attributes = str_replace('class="', 'class="b ', $attributes)
恐怕您需要修复服务器端代码。可能存在重复的
$attributes = str_replace('class="', 'class="b ', $attributes)