Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用不同类属性的同一元素的多个CSS类_Html_Css - Fatal编程技术网

Html 使用不同类属性的同一元素的多个CSS类

Html 使用不同类属性的同一元素的多个CSS类,html,css,Html,Css,我需要为HTML元素指定多个类属性。当我尝试使用以下代码段时,它只应用类a,而不应用类b <html> <head> <style> .a { color:Red; } .b { background-color: Green; } </style> </head> <body cl

我需要为HTML元素指定多个类属性。当我尝试使用以下代码段时,它只应用
类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)