Validation 如何在cakephp中指定CSS文件?

Validation 如何在cakephp中指定CSS文件?,validation,cakephp,Validation,Cakephp,我在W3验证中收到错误“document type不允许元素”link“here”。我在index.ctp文件中指定CSS文件。我具体说明的方式是: <link rel="stylesheet" type="text/css" href="./css/homes.css" /> 在一个布局文件中查看/Layouts/default.ctp 一个(css/screen.css) 不止一个 <?php echo $this->Html->css(array('bo

我在W3验证中收到错误“document type不允许元素”link“here”。我在index.ctp文件中指定CSS文件。我具体说明的方式是:

<link rel="stylesheet" type="text/css" href="./css/homes.css" />

在一个布局文件中查看/Layouts/default.ctp

一个(css/screen.css)


不止一个

<?php echo $this->Html->css(array('bootstrap','screen'));?>

当W3C抱怨“此处的文档类型不允许元素”链接时,这意味着您可能没有将
元素正确放置在
标记中

在CakePHP中,我们通过这样做来正确地发出这些
link
标记:

  • 内联样式:

    //this will echo out the link tag at this exact point
    echo $this->Html->css('your-css-script.css');
    
  • 标题中的Css。假设在主
    layout.ctp
    中有
    echo$this->Html->fetch('css')
    ,所有非内联css链接都将在那里发出

    //this will be placed on top of your layout
    $this->Html->css('your-css-script.css', null, array('inline' => false));
    
  • 多个CSS脚本:

    $this->Html->css(array('css1.css', 'css2.css',..));
    
  • 还请注意,扩展名
    .css
    不是必需的,尽管在那里使用它看起来更好。尝试上述几种组合,并确保您的
    标签位于

    编辑

    为了进一步澄清关于非内联css的疑问,当您进行了此类设置时:

    /View/Layouts/default.ctp

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title><?php echo $title_for_layout ?></title>
        <?php
            echo $this->Html->meta('icon');
            echo $this->fetch('css');
            echo $this->fetch('script');
        ?>
    </head>
    <body></body></html>
    
    <?php $this->Html->css('homes', null, array('inline' => false)); ?>
    Hello world!
    

    homes.css
    应该自动进入
    $this->fetch('css')布局中的代码块。当你希望你的布局简洁,并且在头部包含css,而不是在渲染的html中分散css时,这一点尤其好。

    对不起?你指定的方式是…?啊,我没看到。它的格式不正确。你需要4个空格来开始一个代码块。4个空格是什么意思?你是在HEAD标签中使用这个吗?比我的答案更好,因为它提到了在HEAD中放置css。谢谢。我以为他是从其他地方发出css标签的,所以我想最好让他知道使用非内联css调用的想法。如果某些视图只需要一些css规则,它会使您的主布局更精简,更不混乱。我在index.ctp文件中指定了它,但它仍然显示W3验证中的错误。如果我在标签的默认布局中指定,我的整个布局都会改变。您正在尝试的是内联回显,这意味着您是在
    标签的中间回显。尝试这样做:
    。我假设您的渲染布局中有
    ,或者
    /View/layouts/default.ctp
    。对不起,输入错误。而不是
    $this->Html->fetch('css')
    ,应该是
    $this->fetch('css')
    。有关更多信息,请参阅我编辑的文章。
    <?php $this->Html->css('homes', null, array('inline' => false)); ?>
    Hello world!