英文:
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:
The lines with errors:
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.
<!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:
The lines with errors:
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();
}
答案1
得分: 0
链接元素是一个自闭合元素。
在元素的末尾包含一个 /
。这应该解决错误。
<link rel="stylesheet" href="main.css" />
^ 请参见上面的示例
英文:
The link element is a self terminating element.
Including a /
at the end of the element. This should resolve the error.
<link rel="stylesheet" href="main.css" />
^ See example above
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论