drwj4061 2015-11-27 02:14
浏览 21
已采纳

是否允许将标签放在除常见位置之外的html中的任何位置? [关闭]

I've made a sample code as below code to dynamically create pages using php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>test</title>
    <style type="text/css">
        div {
            width: 200px;
            height: 200px;
            margin: 0 auto;
            background-color: black;
            color: white;
        }
    </style>
</head>
<body>
    <?php 
        echo '<div>' . '<p>' . 'generated by php' . '</div>';
     ?>
</body>
</html>

Then I decided to use an external css file and refer to it by using the LINK tag in the head tag And no styles were applied to the DIV generated. What I did at last was putting the LINK tag anywhere after the PHP code and voila... it worked perfectly. Is there any restrictions about where to put a link tag or not?

  • 写回答

1条回答 默认 最新

  • dongze5043 2015-11-27 02:20
    关注

    The link tag can actually be placed any where on your file, either in the <head> section of your HTML or in the PHP part. This is because the actual formatting using the rules specified in your css file are performed by the browser — the server (and hence PHP) code has nothing to do with how css files are applied. I would check the HTML output generated by your PHP code and the initial output when the <link> was in the <head> section (assuming it was correctly placed in the <head> of the HTML and compare the 2 (from the client browser's perspective, that is!)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题