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

时间:2022-08-26 23:14:47

I am working in a php language . In my database there are normal image and a hover image . I know how to call it from the database but i don't know how to make class so that if i have 2 entries in my database for each ie normal image and hover image and by calling it from the db it will act as a 2 button image with the hover image because I have 2 rows in my column

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

I have defined it in between head .

我在头部之间定义了它。

<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 个解决方案

#1


0  

If you are using inline styles, then you can just use this:

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

<?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>

#2


0  

You can create dynamics CSS using the below

您可以使用以下方法创建动态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">

#1


0  

If you are using inline styles, then you can just use this:

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

<?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>

#2


0  

You can create dynamics CSS using the below

您可以使用以下方法创建动态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">