Trailing solidus not allowed on element link error when I wanted to import external css with link tag in html

huangapple go评论160阅读模式
英文:

Trailing solidus not allowed on element link error when I wanted to import external css with link tag in html

问题

I made an html file but when I wanted to import my css file trow an error like trailing solidus not allowed on element link. But unlike this everything work fine.

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1">
  5. <title>space atack</title>
  6. <link rel="stylesheet" href="main.css">
  7. <meta charset="UTF-8">
  8. </head>
  9. <body>
  10. <script src="js/gameplay.js"></script>
  11. </body>
  12. </html>

Update 1:
I got the errors.
The error of link tag:
Trailing solidus not allowed on element link error when I wanted to import external css with link tag in html
The lines with errors:
Trailing solidus not allowed on element link error when I wanted to import external css with link tag in html

Update 2:
I am sure for Gamestart.js and the background image load but when I tried to add another element in body in index.html (a paragraf) it not showing. Only elements what I writed in js are showing.

main.css file:

  1. #divplay{
  2. text-align: center;
  3. top: 45%;
  4. }
  5. #btnplay{
  6. border-radius: 25px;
  7. background: yellow;
  8. width: 40%;
  9. height: 10%;
  10. }

gameplay.js file:

  1. document.body.style.backgroundImage = "url('img/bg/spatiu.jpg')";
  2. var playdiv = document.createElement('div');
  3. playdiv.id = 'divplay';
  4. document.body.appendChild(playdiv);
  5. var playbtn = document.createElement('button');
  6. playbtn.id = 'btnplay';
  7. playbtn.innerHTML = 'play';
  8. playbtn.addEventListener("click", play);
  9. playdiv.appendChild(playbtn);
  10. function play(){
  11. playbtn.remove();
  12. playdiv.remove();
  13. }
英文:

I made an html file but when I wanted to import my css file trow an error like trailing solidus not allowed on element link. But unlike this everything work fine.

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html&gt;
  3. &lt;head&gt;
  4. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, height=device-height, initial-scale=1, maximum-scale=1&quot;&gt;
  5. &lt;title&gt;space atack&lt;/title&gt;
  6. &lt;link&#160;rel=&quot;stylesheet&quot;&#160;href=&quot;main.css&quot;&gt;
  7. &lt;meta&#160;charset=&quot;UTF-8&quot;&gt;
  8. &lt;/head&gt;
  9. &lt;body&gt;
  10. &lt;script src=&quot;js/gameplay.js&quot;&gt;&lt;/script&gt;
  11. &lt;/body&gt;
  12. &lt;/html&gt;

Update 1:
I got the errors.
The error of link tag:
Trailing solidus not allowed on element link error when I wanted to import external css with link tag in html
The lines with errors:
Trailing solidus not allowed on element link error when I wanted to import external css with link tag in html

Update 2:
I am sure for Gamestart.js and the background image load but when I tried to add another element in body in index.html (a paragraf) it not showing. Only elements what I writed in js are showing.

main.css file:

  1. #divplay{
  2. text-align:&#160;center;
  3. top: 45%;
  4. }
  5. #btnplay{
  6. border-radius:&#160;25px;
  7. background: yellow;
  8. width: 40%;
  9. height: 10%;
  10. }

gameplay.js file:

  1. document.body.style.backgroundImage&#160;=&#160;&quot;url(&#39;img/bg/spatiu.jpg&#39;)&quot;;
  2. var playdiv = document.createElement(&#39;div&#39;);
  3. playdiv.id = &#39;divplay&#39;;
  4. document.body.appendChild(playdiv);
  5. var playbtn = document.createElement(&#39;button&#39;);
  6. playbtn.id = &#39;btnplay&#39;;
  7. playbtn.innerHTML = &#39;play&#39;;
  8. playbtn.addEventListener(&quot;click&quot;, play);
  9. playdiv.appendChild(playbtn);
  10. function play(){
  11. playbtn.remove();
  12. playdiv.remove();
  13. }

答案1

得分: 0

链接元素是一个自闭合元素。

在元素的末尾包含一个 /。这应该解决错误。

&lt;link rel=&quot;stylesheet&quot; href=&quot;main.css&quot; /&gt;

^ 请参见上面的示例

英文:

The link element is a self terminating element.

Including a / at the end of the element. This should resolve the error.

&lt;link rel=&quot;stylesheet&quot; href=&quot;main.css&quot; /&gt;

^ See example above

huangapple
  • 本文由 发表于 2023年6月29日 02:21:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定