I\'m working on a website that uses gulp
to compile and browser sync to keep the browser synchronised with my changes.
The gulp task compiles everything
I installed Bootstrap v. 3.3.7
npm install bootstrap --save
Then I added the needed script files to apps[0].scripts
in the angular-cli.json file:
"scripts": [
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
// And the Bootstrap CSS to the apps[0].styles array
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],
I restarted ng serve
It worked for me.
For a Node.js application, just use this after importing all the required modules in your server file:
app.use(express.static("."));
link rel="stylesheet" href="style.css">
One of the main reasons for the issue is the CSS file which is trying to load isn't a valid CSS file.
Causes:
Check the file which you're trying to load is a valid CSS style sheet (get the server URL of the file from the network tab and hit in a new tab and verify).
Useful info for consideration when using <link> inside the body tag.
Though having a link
tag inside the body is not the standard way to use the tag. But we can use it for page optimization (more information: https://developers.google.com/speed/docs/insights/OptimizeCSSDelivery) / if the business use case demands (when you serve the body of the content and server configured to have to render the HTML page with content provided).
While keeping inside the body tag we have to add the attribute itemProperty
in the link
tag like
<body>
<!-- … -->
<link itemprop="url" href="http://en.wikipedia.org/wiki/The_Catcher_in_the_Rye" />
<!-- … -->
</body>`
For more information on itemProperty
have a look in https://webmasters.stackexchange.com/questions/55130/can-i-use-link-tags-in-the-body-of-an-html-document.
For Node.js applications, check your configuration:
app.use(express.static(__dirname + '/public'));
Notice that /public
does not have a forward slash at the end, so you will need to include it in your href option of your HTML:
href="/css/style.css">
If you did include a forward slash (/public/
) then you can just do href="css/style.css"
.
Comments in your file will trip this. Some minifiers will not remove comments.
ALSO
If you use Node.js and set your static files using express
such as:
app.use(express.static(__dirname + '/public'));
You need to properly address the files.
In my case both were the issue, so I prefixed my CSS links with "/css/styles.css".
Example:
<link type="text/css" rel="stylesheet" href='/css/styles.css">
This solution is perfect as the path is the main issue for CSS not getting rendering
Also for others using Angular-CLI and publishing to a sub-folder on the webserver, check this answer:
When you're deploying to a non-root path within a domain, you'll need to manually update the <base href="/">
tag in your dist/index.html.
In this case, you will need to update to <base href="/sub-folder/">
https://github.com/angular/angular-cli/issues/1080