简体   繁体   中英

My external css file will not load in electron app

first-time asker here. I just started making a desktop application with electron js, and when I try to load my external stylesheet into my index.html file, it will not work. Here is my HTML:

<html lang="en">

<head>
<meta charset="utf-8">
<title>Bundle</title>
<meta name="viewport" content="width=device-width, inital-scale=1.0">
<link rel="stylesheet" type="style.css"
  href="https://raw.githubusercontent.com/AlessioToniolo/Bundle/master/style.css">

</head>

<body>
<div class="header-separation">Hello</div>
<script src="main.js"></script>
<script>
  /* const electron = require('electron');
  const {ipcRenderer} = electron;
  ipcRenderer.send('item:add', item);
  */
  // For other window:
  /* previous code plus
  ipcRenderer.on('item:add', (e, item) => {
  })
  */
</script>
</body>

</html>

When I tried to link to my external stylesheet originally I just used a path instead of a URL but then when it didn't work I tried loading another stylesheet from a CSS framework which did work. What am I doing wrong? Thanks!

Try setting the type="style.css" to type="text/css".

I don't think GitHub allowed that its because the CSP , you should host your CSS on other place like unpkg.com.

Here are GitHub CSP. You can look at your network tab on dev tools

default-src 'none'; style-src 'unsafe-inline'; sandbox

I think it is because used sandbox sandbox described here

and the content type of the request made was text/plain not text/css so it is not executed.

I just tried it out and I can't. First you had typo seperation on you gits, 2 it should be type="text/css"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM