简体   繁体   English

我想先在HTML中加载特定的样式表,然后再加载其他sylesheet和正文。 怎么做?

[英]I want to load specific stylesheet first in Html before other sylesheets and body loads. How to do it?

 <head> <link rel="stylesheet" type="text/css" href="css/style1.css"> <link rel="stylesheet" type="text/css" href="css/style2.css"> <link rel="stylesheet" type="text/css" href="css/style3.css"> </head> <body> All elements </body> <script src="js/jsstyle1.js"></script> <script src="js/jsstyle2.js"></script> <!-- begin snippet: js hide: false console: true babel: false --> 

Here how can I load style1.css and jsstyle1.js first before other stylesheet and elements in body tag loads ? 在这里,如何在加载其他样式表和body标签中的元素之前先加载style1.css和jsstyle1.js?

Linked stylesheets will never be loaded before the <body> contents. 链接的样式表永远不会在<body>内容之前加载。 If you want to load some CSS before the body is rendered, you have to put it in a <style> tag inside the <head> . 如果要在渲染正文之前加载一些CSS,则必须将其放在<head>内的<head> <style>标记中。

Same goes for the script. 脚本也是如此。 Plus, in your example, you put the <script> tags after the <body> tag, which means the browser won't even start loading them until it finished rendering the <body> . 另外,在您的示例中,您将<script>标记放在<body>标记之后,这意味着浏览器甚至在完成渲染<body>之前都不会开始加载它们。 If you want your script to be immediately parsed and executed, you have to put the actual JS code in a <script> element in your HTML markup, again before any content inside the <body> . 如果要立即解析和执行脚本,则必须将实际的JS代码放在HTML标记的<script>元素中,再次 <body>内部的任何内容之前

<html>
<head>
    <style>
        /* Put contents of css/style1.css here */
    </style>
    <link rel="stylesheet" type="text/css" href="css/style2.css">
    <link rel="stylesheet" type="text/css" href="css/style3.css">
</head>
<body>
    <script>
        /* Put contents of js/jsstyle1.js here */
    </script>
    <script src="js/jsstyle2.js"></script>
 </body>
 </html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在每次加载特定页面时运行 JavaScript 脚本。 浏览器:Edge(我正在使用 Tampermonkey) - How do I make a JavaScript script run every time a specific page loads. Browser: Edge (I'm using tampermonkey) 我想在HTML加载之前加载其他网页-AngularJS - I want to load a different webpage before HTML loads - AngularJS 加载时我的页面“结结巴巴”。 我怎样才能解决这个问题? - My page is “stuttering” when it loads. How can I fix this? 我希望php页面首先加载其他信息,然后再执行操作 - I want the php page to load first with other information & then do an operation 如何在实际车身载荷之前显示加载图像? - How do I show a loading image before actual body load? 直到单击事件后才加载画布图像...我想在页面加载时加载,如何? - Canvas images do not load until click event… I want to load when page loads, how? 在页面加载到条件字段drupal模块中之前,如何隐藏HTML元素? - How do I hide an HTML element before the page loads in conditional fields drupal module? 如何在所有其他请求之前加载服务人员? - How do I load a service worker before all other requests? 即使我将 script 标签放在 body 标签的末尾之前,谷歌浏览器也会首先加载 javascript - Google Chrome loads the javascript first even I put the script tag before the end of the body tag 我想在第一次加载时只刷新一次反应页面(功能组件),而不是在任何事件上而是在第一次渲染之后,怎么做? - I want to refresh the react page(functional component) only once when it first loads, not on any event but after first render, how to do that?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM