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

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

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.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1">
<title>space atack</title>
<link rel="stylesheet" href="main.css">
<meta charset="UTF-8">
</head>
<body>
<script src="js/gameplay.js"></script>
</body>
</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:

#divplay{
  text-align: center;
  top: 45%;
}
#btnplay{
  border-radius: 25px;
  background: yellow;
  width: 40%;
  height: 10%;
}

gameplay.js file:

document.body.style.backgroundImage = "url('img/bg/spatiu.jpg')";
var playdiv = document.createElement('div');
playdiv.id = 'divplay';
document.body.appendChild(playdiv);
var playbtn =  document.createElement('button');
playbtn.id = 'btnplay';
playbtn.innerHTML = 'play';
playbtn.addEventListener("click", play);
playdiv.appendChild(playbtn);
function play(){
  playbtn.remove();
  playdiv.remove();
}
英文:

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.

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, height=device-height, initial-scale=1, maximum-scale=1&quot;&gt;
&lt;title&gt;space atack&lt;/title&gt;
&lt;link&#160;rel=&quot;stylesheet&quot;&#160;href=&quot;main.css&quot;&gt;
&lt;meta&#160;charset=&quot;UTF-8&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script src=&quot;js/gameplay.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&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:

#divplay{
  text-align:&#160;center;
  top: 45%;
}
#btnplay{
  border-radius:&#160;25px;
  background: yellow;
  width: 40%;
  height: 10%;
}

gameplay.js file:

document.body.style.backgroundImage&#160;=&#160;&quot;url(&#39;img/bg/spatiu.jpg&#39;)&quot;;
var playdiv = document.createElement(&#39;div&#39;);
playdiv.id = &#39;divplay&#39;; 
document.body.appendChild(playdiv);
var playbtn =  document.createElement(&#39;button&#39;);
playbtn.id = &#39;btnplay&#39;;
playbtn.innerHTML = &#39;play&#39;;
playbtn.addEventListener(&quot;click&quot;, play);
playdiv.appendChild(playbtn);
function play(){
  playbtn.remove();
  playdiv.remove();
}

答案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:

确定