WebDesign / inde.html
WebBuilder's picture
Update inde.html
d5a0951 verified
Raw History Blame Contribute Delete
1.39 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Preprocessor Example</title>
<style id="processed-css"></style>
</head>
<body>
<div class="container">
<h1>Hello, World!</h1>
<p>This is a simple example of using a CSS preprocessor.</p>
</div>
<script>
// Define variables
const variables = {
primaryColor: '#007bff',
secondaryColor: '#6c757d',
};
// Define mixins
const mixins = {
flexCenter: `
display: flex;
justify-content: center;
align-items: center;
`,
};
// Parse and process CSS
function preprocessCSS(css) {
// Resolve variables
for (const [key, value] of Object.entries(variables)) {
css = css.replace(new RegExp(`\\$${key}`, 'g'), value);
}
// Expand mixins
for (const [key, value] of Object.entries(mixins)) {
css = css.replace(new RegExp(`@mixin ${key}`, 'g'), value);
}
return css;
}
// Example usage
const inputCSS = `
body {
background-color: $primaryColor;
color: $secondaryColor;
@mixin flexCenter;
}
`;
const processedCSS = preprocessCSS(inputCSS);
document.getElementById('processed-css').innerText = processedCSS;
</script>
</body>
</html>