Text Editor

Creating a complete responsive text editor with a download option for .txt files involves HTML for structure, CSS for styling, and JavaScript for functionality. Below is a simple implementation of a text editor that allows users to write text and download it as a .txt file. ### HTML (index.html) ```html Text Editor

Simple Text Editor

``` ### CSS (styles.css) ```css * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: Arial, sans-serif; background-color: #f0f0f0; color: #333; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); text-align: center; width: 90%; max-width: 500px; } h1 { color: #4a90e2; margin-bottom: 20px; } textarea { width: 100%; height: 300px; border: 2px solid #4a90e2; border-radius: 5px; padding: 10px; font-size: 16px; resize: none; margin-bottom: 20px; } button { background-color: #4a90e2; color: white; border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } button:hover { background-color: #357ab8; } ``` JavaScript (script.js) ```javascript document.getElementById('download').onclick = () => { const text = document.getElementById('editor').value; const blob = new Blob([text], { type: 'text/plain' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = 'document.txt'; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; ``` Explanation: 1. **HTML**: Creates a basic structure with a textarea for text input and a button to download the text as a .txt file. 2. **CSS**: Provides colorful styling for the interface, ensuring it is visually appealing and responsive. 3. **JavaScript**: Handles the download functionality. It creates a blob from the textarea content, generates a temporary link, and triggers a download when the button is clicked. Usage: 1. Save the code in three separate files (`index.html`, `styles.css`, and `script.js`). 2. Open `index.html` in a web browser. 3. Type your text in the editor and click the "Download as .txt" button to download your text file. Note: This implementation provides a simple text editor with basic functionality. You can enhance it by adding features like text formatting, saving the content to local storage, or improving the UI further.

Comments

Popular posts from this blog

Screen Recorder Tool

SpeedTest Checker Tool

Text to Speech Converter