【问题标题】:create a css dynamically using image and hover image使用图像和悬停图像动态创建 CSS
【发布时间】:2013-11-27 06:34:32
【问题描述】:

我正在使用php 语言工作。在我的数据库中有普通图像和悬停图像。我知道如何从数据库中调用它,但我不知道如何创建类,这样如果我的数据库中有 2 个条目,即每个普通图像和悬停图像,并从数据库中调用它,它将充当 2带有悬停图像的按钮图像,因为我的column 中有 2 个rows

我在 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>

【问题讨论】:

  • 你在 PHP 中尝试过什么。这并不能真正告诉我们任何事情
  • @AndyHolmes 我被困在这一点上只是我如何在 css 中使用我的 db 值
  • 请更好地解释你想要做什么。
  • 我猜是“。”您文本中的字符可能会帮助我们大多数人更好地理解您的问题。请改进!
  • 我的数据库中有一个简单的图像和一个悬停图像,我想从数据库中调用它,它将充当按钮图像

标签: php html css


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 不,我没有使用内联样式.......我在我的头部之间使用内部 css
    • 也称为...内联样式
    • 内联样式大多写在标签本身的style属性中。这种风格称为internalembedded 风格。
    • 如果我有 2 行并且我想为每一行创建一个新类......有什么办法吗
    • 从数据库调用信息并使用foreach循环创建类?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 2013-10-30
    • 2015-07-04
    • 2013-03-23
    相关资源
    最近更新 更多