Text Editor
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}
.editor-container {
width: 80%;
max-width: 800px;
background-color: white;
border: 1px solid #ddd;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.toolbar {
display: flex;
border-bottom: 1px solid #ddd;
background-color: #f9f9f9;
padding: 10px;
}
.toolbar button {
background: none;
border: none;
padding: 5px 10px;
margin-right: 5px;
cursor: pointer;
font-size: 16px;
}
.toolbar button:hover {
background-color: #e0e0e0;
}
#editor {
padding: 20px;
min-height: 300px;
outline: none;
}
function execCmd(command, value = null) {
document.execCommand(command, false, value);
}
function downloadText() {
const text = document.getElementById("editor").innerText;
const blob = new Blob([text], { type: "text/plain" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "document.txt";
link.click();
}
// Ensure the contenteditable div retains focus on click
document.getElementById('editor').addEventListener('click', function() {
this.focus();
});
No comments:
Post a Comment