External CSS is a method of styling web pages by placing CSS rules in a separate file with a .css extension, which is then linked to one or more HTML documents. This approach allows you to define styles for an entire website in one file, ensuring consistency and making updates efficient—changing a single CSS file updates all linked pages.
To use external CSS:
Create a file (e.g.,
styles.css) using any text editor and save it with the.cssextension.In your HTML file, add the
<link>element inside the<head>section:<link rel="stylesheet" href="styles.css">Ensure the CSS file is in the correct location relative to the HTML file (same folder or a specified path).
Key advantages of external CSS:
Consistent design across multiple pages.
Efficient maintenance: Update styles globally with one file.
Faster loading after the first visit due to browser caching.
Cleaner HTML: Keeps styling separate from content.
External CSS is the most recommended method for larger websites, as it promotes separation of concerns, improves code organization, and enhances scalability.
The IFRAME solution works like this:
In your main HTML file, you'll have your DIV:
<div id="myspecialdiv">
<iframe width="100%" height="100%" frameborder="0" src="divcontent.html"></iframe>
</div>
Style that as you need it. The divcontent.html file should be a complete HTML file, including the content of the DIV tag, and a LINK using your external stylesheet:
<html>
<head>
<link rel="stylesheet" href="path/to/external/stylesheet.css" />
</head>
<body>
<!-- The contents of your DIV -->
</body>
</html>
Answer from Gareth Cornish on Stack Overflowcss - Div with external stylesheet? - Stack Overflow
External Style Sheet
How to Inject External CSS, CSS Libraries or CSS Pre-Processors in Outsystems? | OutSystems
Linking to External CSS files
Videos
The IFRAME solution works like this:
In your main HTML file, you'll have your DIV:
<div id="myspecialdiv">
<iframe width="100%" height="100%" frameborder="0" src="divcontent.html"></iframe>
</div>
Style that as you need it. The divcontent.html file should be a complete HTML file, including the content of the DIV tag, and a LINK using your external stylesheet:
<html>
<head>
<link rel="stylesheet" href="path/to/external/stylesheet.css" />
</head>
<body>
<!-- The contents of your DIV -->
</body>
</html>
If you can work with HTML5, you could try using scoped styles. You could include the CSS inside the div, having it affect only its parent:
<div>
<style scoped>
// Styles here
</style>
</div>