【问题标题】:Output Div Tag CSS Style Not Working输出 div 标签 CSS 样式不起作用
【发布时间】:2012-01-26 16:21:11
【问题描述】:

好的,这就是正在发生的事情。为 Wordpress 使用 Moneypress LE 插件。我能够通过文件“CSL-products_class.php”有效地输出 html,用于带有 Div 标签“buynow”的“立即购买”按钮。问题是无法加载通过我附加的样式表关联的样式。

您可以在查看我的网站http://www.dustinschmidt.com 上的源代码时检查其中一种产品来发现问题。 html 在那里,但没有样式。

添加了以下代码块:

$product_output[] = "<div class=\"{$this->css_prefix}-buynow\">";
        $product_output[] =
                "<a href=\"{$product->web_urls[0]}\" rel=nofollow target=\"cyber-    sprocket-labs\">".'</a>';
        $product_output[] = '</div>';

这是“CSL-products_class.php”现在的样子。

<?php


class wpCSL_products__mpcj {


function __construct($params) {

    // Properties with default values
    //
    $this->columns = 1;                 // How many columns/row in our display output.

    foreach ($params as $name => $value) {
        $this->$name = $value;
    }
 }

/*-------------------------------------
 * method: display_products
 *
 * Legacy Panhandler stuff that will eventually come out.
 * This method generates the HTML that will be used to display
 * the product list in WordPress when it renders the page.
 *
 */
function display_products($products) {
    $product_output[] = '';
    $moneyFormat = get_option($this->prefix.'-money_format');
    $linkModifiers = get_option($this->prefix.'-link_modifiers');
    $currCol = 0;        
    foreach ($products as $product) {

        // If we are on the first column, start a new row div
        //
        if ($currCol == 0) {
            $product_output[] = '<div class="'.$this->css_prefix.'-row">';
        }

        $product_output[] = "<div class=\"{$this->css_prefix}-product\">";
        $product_output[] = "<h3>{$product->name}</h3>";
        $product_output[] = "<div class=\"{$this->css_prefix}-left\">";
        $product_output[] = "<a href=\"{$product->web_urls[0]}\" target=\"cyber-sprocket-labs\" $linkModifiers>";
        $product_output[] = "<img src=\"{$product->image_urls[0]}\" alt=\"{$product->name}\" title=\"{$product->name}\" />";
        $product_output[] = '</a><br/>';
        $product_output[] = '<div class="'.$this->css_prefix.'-zoombox">';
        $product_output[] = '<a class="thickbox" href="'.$product->image_urls[0].'">&nbsp;</a>';
        $product_output[] = '</div>';
        $product_output[] = '</div>';
        $product_output[] = '<div class="'.$this->css_prefix . '-right">';
        $product_output[] = '<p class="' . $this->css_prefix . '-desc" >'.$product->description.'</p>';
        $product_output[] = '<p class="' . $this->css_prefix . '-price">'.$product->currency;
        if (function_exists('money_format') &&  ($moneyFormat != '')) {
            $product_output[] =
                "$ <a href=\"{$product->web_urls[0]}\" rel=nofollow target=\"cyber-sprocket-labs\" $linkModifiers>".
                trim(money_format($moneyFormat, (float)$product->price)) .
                '</a>';
        } else {
            $product_output[] =
                "$ <a href=\"{$product->web_urls[0]}\" rel=nofollow target=\"cyber-sprocket-labs\">".
                trim(number_format((float)$product->price, 2)) .
                '</a>';
        }
        $product_output[] = '</p>';
        $product_output[] = "<div class=\"{$this->css_prefix}-buynow\">";
        $product_output[] =
                "<a href=\"{$product->web_urls[0]}\" rel=nofollow target=\"cyber-sprocket-labs\">".'</a>';
        $product_output[] = '</div>';

        $product_output[] = '</div>';
        $product_output[] = '<div class="'.$this->css_prefix.'-cleanup"></div>';            
        $product_output[] = '</div>';

        // Move to the next column, if we already hit the max desired
        // output columns, close the row and get ready for a new one
        //
        $currCol++;            
        if ($currCol == $this->columns) {
            $currCol = 0;
            $product_output[] = '</div>';
        }
    }

    // We did not end output on the last column
    // so we need to close the row div
    //
    if ($currCol > 0) {
        $currCol = 0;
        $product_output[] = '</div>';
    }

    return implode($product_output);
 }    


}

最后是我的 div 标签“buynow”的 CSS。

.csl_themes-buynow{background:url("../../core/images/buy-now.png") no-repeat;width:175px;height:64px;float:left}

感谢您的帮助, 尘土飞扬

【问题讨论】:

  • 其他所有类都可以正常加载吗?例如,"
    css_prefix}-product\">" 是否加载了正确的类?
  • 是的,所有其他类都加载了。这个buynow 类是我要插入的唯一自定义类。看起来样式表本身没有加载,因为当我单击 中的链接时无法访问它。嗯。

标签: css html styles stylesheet


【解决方案1】:

通过访问http://www.dustinschmidt.com/watches/ 并查看源代码,我可以看到,“csl_themes-buynow”类在多个 div 中被引用。比如……

<div class="csl_themes-buynow"><a href="http://www.anrdoezrs.net/click-5462802-10535303?url=http%3A%2F%2Fwww.ashford.com%2Fashford%2Fbrowse%2FproductDetail.jsp%3FproductId%3D96B139%26source%3D406010001&cjsku=96B139" rel=nofollow target="cyber-sprocket-labs"></a></div>

所以,看起来您的 CSS 中的某些设置可能不正确。

试着在那个 CSS 上加一个响亮的边框(比如border: 10px solid limegreen),看看它是否显示出来......

【讨论】:

  • 非常感谢您查看这个 Zack。尝试添加边框,我的浏览器甚至没有确认 CSS 类。你认为我可能需要在插件中注册 CSS 后缀“-buynow”吗?此样式表未正确加载 ,似乎可能是问题所在。
  • 我不确定...所以,“.csl_themes-buynow”在它自己的样式表中?您是否有多个正在使用的样式表?我建议尝试将“.csl_themes-buynow”放入您知道页面上正在加载的样式表中。
  • 设法弄明白了。新手总复发。 CSS 版本控制没有更新新样式。将我的 CSS 标头更改为
  • 很高兴听到这个消息。您应该将此评论发布为您的答案,然后在可能的情况下将其标记为已接受的答案,因为它可能会帮助下一个遇到类似问题的人......
猜你喜欢
相关资源
最近更新 更多
热门标签