Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/components/CodePlayground.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ export default function CodePlayground({ language = 'javascript', initialCode =
const executeCSS = () => {
try {
if (iframeRef.current) {
const htmlContent = `
const iframeDoc = iframeRef.current.contentDocument || iframeRef.current.contentWindow.document;
iframeDoc.open();
iframeDoc.write(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>${code}</style>
</head>
<body>
<div class="card">
Expand All @@ -120,11 +121,13 @@ export default function CodePlayground({ language = 'javascript', initialCode =
</div>
</body>
</html>
`;
const iframeDoc = iframeRef.current.contentDocument || iframeRef.current.contentWindow.document;
iframeDoc.open();
iframeDoc.write(htmlContent);
`);
iframeDoc.close();

const styleEl = iframeDoc.createElement('style');
styleEl.textContent = code;
iframeDoc.head.appendChild(styleEl);

setOutput([{ type: 'info', message: 'CSS rendered successfully' }]);
}
} catch (err) {
Expand Down
Loading