我怎样才能让php文件在zend中用作css?

发布于 2024-12-17 06:49:31 字数 1308 浏览 4 评论 0原文

我参考以下链接,

如何在 php 中包含 CSS?

我正在使用 zend。在我的模板 phtml 文件中,我包括如下

<style type="text/css">
    input[type="button"] {
        background-image: url("<?php echo SITE_URL; ?>/images/sub_bg-green.jpg");
        background-repeat: repeat-x;
        border: 1px solid #4B8109;
        font-size: 11px;
        margin-right: 10px;
        padding: 3px 10px;
        color:#000;   
    }
</style>

代码 将给出基本 url。当我包含内部模板页面时,这有效。现在我正在做 w3c 验证,它给出了错误。所以我尝试将所有样式放入 product_details.php 中,并使用以下代码将其包含在 phtml 文件中,

<?php $this->headLink()->appendStylesheet(BASE_URL . 'css/templates/product_details.php');  ?>

当我查看文件的源代码时,我没有得到基本网址,而是得到了类似的结果下面,

<style type="text/css">
    input[type="button"] {
        background-image: url("SITE_URL/images/sub_bg-green.jpg");
        background-repeat: repeat-x;
        border: 1px solid #4B8109;
        font-size: 11px;
        margin-right: 10px;
        padding: 3px 10px;
        color:#000;   
    }
</style>

我如何在 css 中包含 php 代码,同时它应该位于 内,以便我们可以实现 w3c 验证。请就此提出建议。

I refer the following link,

How can I include CSS in php?

I am using zend. In my template phtml file, i include like below,

<style type="text/css">
    input[type="button"] {
        background-image: url("<?php echo SITE_URL; ?>/images/sub_bg-green.jpg");
        background-repeat: repeat-x;
        border: 1px solid #4B8109;
        font-size: 11px;
        margin-right: 10px;
        padding: 3px 10px;
        color:#000;   
    }
</style>

code <?php echo SITE_URL; ?> will give base url. This works when i include inside template page. Now i am working on w3c validation which gives error. so i tried to put all styles in product_details.php and include it in phtml file by using following code,

<?php $this->headLink()->appendStylesheet(BASE_URL . 'css/templates/product_details.php');  ?>

when i view the source code of file, i did not get the base url, instead i got like below,

<style type="text/css">
    input[type="button"] {
        background-image: url("SITE_URL/images/sub_bg-green.jpg");
        background-repeat: repeat-x;
        border: 1px solid #4B8109;
        font-size: 11px;
        margin-right: 10px;
        padding: 3px 10px;
        color:#000;   
    }
</style>

How can i include php code in css and at the same time it should be inside <HEAD> so that we can achieve w3c validation.Kindly advice on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离去的眼神 2024-12-24 06:49:31

为什么不只使用 CSS 文件到图像的相对链接,例如

/* Assuming CSS file is css/templates/product_details.css */

background-image: url(../../images/sub_bg-green.jpg);

...或者甚至是绝对 URL(如果您的图像始终位于同一位置)

background-image: url(/images/sub_bg-green.jpg);

然后只需使用 HeadLink 视图链接 CSS 文件帮手

<?php $this->headLink()->appendStylesheet(
    $this->baseUrl('css/templates/product_detail.css')); ?>

Why not just use relative links from the CSS file to the images, eg

/* Assuming CSS file is css/templates/product_details.css */

background-image: url(../../images/sub_bg-green.jpg);

... or even an absolute URL if your images are always in the same place

background-image: url(/images/sub_bg-green.jpg);

You then just link the CSS file using the HeadLink view helper

<?php $this->headLink()->appendStylesheet(
    $this->baseUrl('css/templates/product_detail.css')); ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文