使用图像和悬停图像动态创建一个CSS

时间:2013-11-14 09:52:47

标签: php html css

我使用的是php语言。在我的数据库中有正常图像和悬停图像。我知道如何从数据库中调用它,但我不知道如何创建类,以便如果我的数据库中有两个条目,即每个正常图像和悬停图像,并通过从db调用它将充当2带有悬停图片的按钮图片,因为我的rows

中有2 column

我在头部之间定义了它。

<style>
.n1{background:url(../images/no.png); 
 width:110px; height:29px; 
 float:left;
 margin-top:6px
 }

 .n1:hover{
  background:url(../images/no-h.png);
   }
 </style>

2 个答案:

答案 0 :(得分:0)

如果您使用的是内联样式,那么您可以使用它:

<?php $var = 'no'; ?>
<style>
  .n1{background:url(../images/<?php echo $var ?>.png); 
 width:110px; height:29px; 
 float:left;
 margin-top:6px
 }

 .n1:hover{
  background:url(../images/<?php echo $var ?>-h.png);
   }
</style>

答案 1 :(得分:0)

您可以使用以下

创建动态CSS
Define Content-Type on the top of your .css.php file:
<?
header('Content-Type: text/css');
// print out your php-driven css...
?>
 and call the file like this ..

<link rel="stylesheet" type="text/css" media="screen" href="CSS_PATH/name-of-file.css.php">