Link stylesheet didn't work
See original GitHub issueHi! This plugin is so usefull.
I’m trying to link a external CSS to my email template. Before this step the CSS was in HEAD section and this want a problem. But i want use SASS as pre-processor to make it simpler. So i need a external CSS file. But when i try to include the CSS file, inline-css print this in console:
{ Error: getaddrinfo ENOTFOUND main.css main.css:80
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'main.css',
host: 'main.css',
port: 80,
response: undefined }
This is the code:
const fs = require('fs');
const inlineCss = require('inline-css');
fs.readFile('entry.html', 'utf8', (err, data) => {
inlineCss(data, { url: './', removeHtmlSelectors: true }).then(html => {
fs.writeFile('index.html', html);
}).catch(function(reason) {
console.log(reason);
});
});
And this is the HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="main.css" rel="stylesheet">
</head>
<body>
...
</body>
</html>
I have also tried ‘/’, ‘.’.
I can’t understand where is the problem. In the example i link the file in the same way.
Thanks in advance!
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Linking CSS doesn't work - Stack Overflow
Try to make the link the same level as index.html directed to the css folder.
Read more >How to fix CSS not linking to your HTML document
When you add an external CSS file to your HTML document, you need to add the rel="stylesheet" attribute to the <link> tag to...
Read more >CSS style sheet not loading or linking with HTML
I'm using HTML with Bootstrap all loads up fine, but when a style sheet is added to the HTML code sometimes it doesnt...
Read more >How to add CSS - W3Schools
Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section. Example. External...
Read more >How to Fix CSS file is not Working with HTML in Chrome
Fix CSS file is not Working with HTML in Chrome | Problem Solved Show SupportBuy Me a COFFEE: https://buymeacoffee.com/Webjahin ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @AFerreli I had the same funny issue with the script looking one directory up from where I wanted. This was the solution:
url = 'file://'+__dirname + '/' +path.dirname(file)+ '/';
The slash at the end made things work fine for me. It makes sense when you think about how this option is designed for arbitrary href urls, that a trailing slash would be good.
This seems a little odd to have to pass in
file://
and__dirname
or to have to use path module. In the most basic of setup using a linked stylesheet. Is there a strong use-case for the module not doing this for the user, so that it uses the current directory of the process?