read below code carefully and make changes into it as i suggest. <!DOCTYPE html> <html…
- User
read below code carefully and make changes into it as i suggest.
.notes-container { display: flex; flex-wrap: wrap; justify-content: center; margin: auto; padding: 20px; width: 100%; } .note { margin: 20px; padding: 60px 20px 20px 20px; border-radius: 5px 5px 5px 20px; /* folder-like shape */ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); width: 240px; position: relative; overflow: hidden; background-color: #FFFFD1; /* pastel yellow default color */ min-height: 150px; height: auto; } .note textarea { width: 100%; height: calc(100% - 70px); /* Adjusts to fill available space minus padding */ resize: none; border: none; background: transparent; font-family: inherit; outline: none; display: block; } .toolbar { position: absolute; top: 10px; left: 10px; display: flex; gap: 10px; } .toolbar button, .toolbar img { width: 20px; height: 20px; cursor: pointer; background: none; border: none; color: #555; filter: invert(40%); /* gray tint to match font */ } .add-note-btn, .export-import button { margin: 5px; padding: 10px 20px; font-size: 16px; border: none; border-radius: 5px; cursor: pointer; background-color: #4CAF50; color: white; } .date-time { position: absolute; top: 10px; right: 10px; font-size: 0.8em; color: #555; } .export-import { position: fixed; top: 20px; left: 20px; display: flex; flex-direction: column; gap: 10px; } .color-picker-container { display: flex; gap: 5px; margin-left: 20px; margin-top: 20px; } .color-choice { width: 20px; height: 20px; border-radius: 50%; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); } </style><div class="export-import"> <button class="add-note-btn" onclick="addNote()">Add Note</button> <div class="color-picker-container" id="color-picker-container"> <!-- Pastel color choices --> <div class="color-choice" style="background-color: #FFDDC1;" onclick="selectColor('#FFDDC1')"></div> <div class="color-choice" style="background-color: #FFCCD2;" onclick="selectColor('#FFCCD2')"></div> <div class="color-choice" style="background-color: #D5AAFF;" onclick="selectColor('#D5AAFF')"></div> <div class="color-choice" style="background-color: #C1E1FF;" onclick="selectColor('#C1E1FF')"></div> <div class="color-choice" style="background-color: #C1FFC1;" onclick="selectColor('#C1FFC1')"></div> <div class="color-choice" style="background-color: #FFFFD1;" onclick="selectColor('#FFFFD1')"></div> <div class="color-choice" style="background-color: #D1FFF2;" onclick="selectColor('#D1FFF2')"></div> </div> <button onclick="exportNotes()">Export</button> <input type="file" id="importFile" onchange="importNotes()" style="display: none;"> <button onclick="document.getElementById('importFile').click()">Import</button> </div> <div id="notes-container" class="notes-container"></div> <script> let selectedColor = '#FFFFD1'; // pastel yellow default color function addNote() { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const toolbar = document.createElement('div'); toolbar.className = 'toolbar'; toolbar.innerHTML = ` <button onclick="document.execCommand('bold', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/bold.png" alt="Bold" title="Bold"> </button> <button onclick="document.execCommand('italic', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/italic.png" alt="Italic" title="Italic"> </button> <button onclick="document.execCommand('underline', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/underline.png" alt="Underline" title="Underline"> </button> <button onclick="deleteNote(this)"> <img src="https://img.icons8.com/ios-filled/50/000000/trash.png" alt="Delete" title="Delete"> </button> `; note.appendChild(toolbar); const textarea = document.createElement('textarea'); textarea.placeholder = 'Enter your note here...'; textarea.oninput = function () { this.style.height = 'auto'; this.style.height = this.scrollHeight + 'px'; }; note.appendChild(textarea); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; const now = new Date(); const formattedDate = now.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }); const formattedTime = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', hour12: true }); dateTime.textContent = `${formattedDate} ${formattedTime}`; note.appendChild(dateTime); noteContainer.appendChild(note); } function selectColor(color) { selectedColor = color || '#FFFFD1'; // default to pastel yellow } function deleteNote(button) { const note = button.closest('.note'); note.remove(); } function exportNotes() { let notesData = ''; const notes = document.querySelectorAll('.note textarea'); notes.forEach(note => { notesData += note.value + '\n\n---\n\n'; }); const blob = new Blob([notesData], { type: 'text/plain' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'notes.txt'; a.click(); } function importNotes() { const fileInput = document.getElementById('importFile'); const file = fileInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (e) { const content = e.target.result; const notesData = content.split('\n\n---\n\n'); notesData.forEach(text => { if (text.trim()) { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const toolbar = document.createElement('div'); toolbar.className = 'toolbar'; toolbar.innerHTML = ` <button onclick="document.execCommand('bold', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/bold.png" alt="Bold" title="Bold"> </button> <button onclick="document.execCommand('italic', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/italic.png" alt="Italic" title="Italic"> </button> <button onclick="document.execCommand('underline', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/underline.png" alt="Underline" title="Underline"> </button> <button onclick="deleteNote(this)"> <img src="https://img.icons8.com/ios-filled/50/000000/trash.png" alt="Delete" title="Delete"> </button> `; note.appendChild(toolbar); const textarea = document.createElement('textarea'); textarea.value = text.trim(); note.appendChild(textarea); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; const now = new Date(); const formattedDate = now.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }); const formattedTime = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', hour12: true }); dateTime.textContent = `${formattedDate} ${formattedTime}`; note.appendChild(dateTime); noteContainer.appendChild(note); } }); }; reader.readAsText(file); } } </script> - Assistant
Sure, please let me know what changes you would like to make to the code.
- User
Do below changes
- fix left side of page.
- reduce button size and for color pallet use 4x4 rule.
- text feature button size should be as same as time and date font.
- Delete button should be next to time and date
- whenever i add any note start adding note from left side
- add font button to change font size to sticky notes. use "+", "-" icon and position it on right mid to notes also don't forget to format it as as same as time and date font.
- whenever i export data, use time and date as header.
make above changes in code but do not change my original theme.
- Assistant
Here is the updated code incorporating your requested changes:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sticky Notes</title> <style> body { font-family: Arial, sans-serif; background-color: #f9f9f9; margin: 0; padding: 0; } .notes-container { display: flex; flex-wrap: wrap; justify-content: flex-start; /* Align notes from the left side */ margin: auto; padding: 20px; width: 100%; } .note { margin: 20px; padding: 60px 20px 20px 20px; border-radius: 5px 5px 5px 20px; /* folder-like shape */ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); width: 240px; position: relative; overflow: hidden; background-color: #FFFFD1; /* pastel yellow default color */ min-height: 150px; height: auto; } .note textarea { width: 100%; height: calc(100% - 70px); /* Adjusts to fill available space minus padding */ resize: none; border: none; background: transparent; font-family: inherit; outline: none; display: block; } .toolbar { position: absolute; top: 10px; left: 10px; display: flex; gap: 5px; /* Smaller gap for smaller buttons */ } .toolbar button, .toolbar img { width: 15px; height: 15px; cursor: pointer; background: none; border: none; color: #555; filter: invert(40%); /* gray tint to match font */ } .add-note-btn, .export-import button { margin: 5px; padding: 8px 16px; /* Reduced button size */ font-size: 14px; /* Reduced font size */ border: none; border-radius: 5px; cursor: pointer; background-color: #4CAF50; color: white; } .date-time { position: absolute; top: 10px; right: 40px; /* Adjust to accommodate delete button */ font-size: 0.8em; color: #555; } .delete-button { position: absolute; top: 10px; right: 10px; width: 15px; height: 15px; cursor: pointer; background: none; border: none; color: #555; filter: invert(40%); } .export-import { position: fixed; top: 20px; left: 10px; display: flex; flex-direction: column; gap: 10px; } .color-picker-container { display: grid; grid-template-columns: repeat(4, 1fr); /* 4x4 color palette */ grid-template-rows: repeat(2, 1fr); /* Adjust for 4x4 grid */ gap: 5px; margin-left: 0px; /* Reduced left margin */ margin-top: 20px; } .color-choice { width: 20px; height: 20px; border-radius: 50%; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); } .font-size-control { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; color: #555; } .font-size-control button { background: none; border: none; cursor: pointer; color: #555; font-size: 0.8em; /* Match size with date-time */ } </style> </head> <body> <div class="export-import"> <button class="add-note-btn" onclick="addNote()">Add Note</button> <div class="color-picker-container" id="color-picker-container"> <!-- Pastel color choices --> <div class="color-choice" style="background-color: #FFDDC1;" onclick="selectColor('#FFDDC1')"></div> <div class="color-choice" style="background-color: #FFCCD2;" onclick="selectColor('#FFCCD2')"></div> <div class="color-choice" style="background-color: #D5AAFF;" onclick="selectColor('#D5AAFF')"></div> <div class="color-choice" style="background-color: #C1E1FF;" onclick="selectColor('#C1E1FF')"></div> <div class="color-choice" style="background-color: #C1FFC1;" onclick="selectColor('#C1FFC1')"></div> <div class="color-choice" style="background-color: #FFFFD1;" onclick="selectColor('#FFFFD1')"></div> <div class="color-choice" style="background-color: #D1FFF2;" onclick="selectColor('#D1FFF2')"></div> </div> <button onclick="exportNotes()">Export</button> <input type="file" id="importFile" onchange="importNotes()" style="display: none;"> <button onclick="document.getElementById('importFile').click()">Import</button> </div> <div id="notes-container" class="notes-container"></div> <script> let selectedColor = '#FFFFD1'; // pastel yellow default color function addNote() { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const toolbar = document.createElement('div'); toolbar.className = 'toolbar'; toolbar.innerHTML = ` <button onclick="document.execCommand('bold', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/bold.png" alt="Bold" title="Bold"> </button> <button onclick="document.execCommand('italic', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/italic.png" alt="Italic" title="Italic"> </button> <button onclick="document.execCommand('underline', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/underline.png" alt="Underline" title="Underline"> </button> `; note.appendChild(toolbar); const textarea = document.createElement('textarea'); textarea.placeholder = 'Enter your note here...'; textarea.oninput = function () { this.style.height = 'auto'; this.style.height = this.scrollHeight + 'px'; }; note.appendChild(textarea); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; const now = new Date(); const formattedDate = now.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }); const formattedTime = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', hour12: true }); dateTime.textContent = `${formattedDate} ${formattedTime}`; note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = ` <img src="https://img.icons8.com/ios-filled/50/000000/trash.png" alt="Delete" title="Delete"> `; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } function selectColor(color) { selectedColor = color || '#FFFFD1'; // default to pastel yellow } function deleteNote(button) { const note = button.closest('.note'); note.remove(); } function changeFontSize(button, action) { const note = button.closest('.note'); const textarea = note.querySelector('textarea'); const currentSize = parseFloat(window.getComputedStyle(textarea).fontSize); if (action === 'increase') { textarea.style.fontSize = (currentSize + 1) + 'px'; } else if (action === 'decrease') { textarea.style.fontSize = (currentSize - 1) + 'px'; } } function exportNotes() { let notesData = ''; const notes = document.querySelectorAll('.note'); notes.forEach(note => { const dateTime = note.querySelector('.date-time').textContent; const text = note.querySelector('textarea').value; notesData += `Date/Time: ${dateTime}\n${text}\n\n---\n\n`; }); const blob = new Blob([notesData], { type: 'text/plain' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'notes.txt'; a.click(); } function importNotes() { const fileInput = document.getElementById('importFile'); const file = fileInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (e) { const content = e.target.result; const notesData = content.split('\n\n---\n\n'); notesData.forEach(noteSection => { const [header, ...textArray] = noteSection.split('\n'); const text = textArray.join('\n').trim(); if (text) { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const textarea = document.createElement('textarea'); textarea.value = text; note.appendChild(textarea); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; dateTime.textContent = header.replace('Date/Time: ', ''); note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = ` <img src="https://img.icons8.com/ios-filled/50/000000/trash.png" alt="Delete" title="Delete"> `; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } }); }; reader.readAsText(file); } } </script> </body> </html>Changes Made:
- Notes now start from the left.
- Button sizes are reduced, and the color palette follows a 4x4 layout.
- Text formatting buttons are now smaller, matching the size of the time and date font.
- The delete button is placed next to the date-time display.
- Notes start aligning from the left.
- Added buttons to increase or decrease font size, positioned centrally on the right side of each note.
- When exporting data, the date and time are included as headers for each note.
These changes should meet your specified requirements while maintaining the original theme.
- User
Nice, but need some rectifications in this code. Do as below
1 The bold Italic and underline feture is not working. 2 also add bullet point feature next to bold italic and underline use same formating. 3 the delete buttone sixe is also the same as bold Italic and underline 4 when i am adding notes its hidding my add and other button for it keep margin in it.
do the changes and remember oy theme rule.
- Assistant
Let's address the issues you've mentioned:
- To make the text formatting (bold, italic, underline) work in a
contenteditableenvironment instead of usingtextarea, we'll switch to usingcontenteditable="true"on adiv. - Add a bullet point feature next to the bold, italic, and underline buttons.
- Ensure the delete button is formatted the same size as the other text feature buttons.
- Set a margin to prevent the notes from overlapping the tool buttons at the top.
Here is the revised code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sticky Notes</title> <style> body { font-family: Arial, sans-serif; background-color: #f9f9f9; margin: 0; padding: 0; } .notes-container { display: flex; flex-wrap: wrap; justify-content: flex-start; /* Align notes from the left side */ margin: auto; padding: 20px; width: 100%; margin-top: 150px; /* Add top margin to avoid overlap */ } .note { margin: 20px; padding: 60px 20px 20px 20px; border-radius: 5px 5px 5px 20px; /* folder-like shape */ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); width: 240px; position: relative; overflow: hidden; background-color: #FFFFD1; /* pastel yellow default color */ min-height: 150px; } .note [contenteditable="true"] { width: 100%; height: calc(100% - 70px); /* Adjusts to fill available space minus padding */ overflow-y: auto; outline: none; border: none; background: transparent; font-family: inherit; } .toolbar { position: absolute; top: 10px; left: 10px; display: flex; gap: 5px; /* Smaller gap for smaller buttons */ } .toolbar button, .toolbar img { width: 15px; height: 15px; cursor: pointer; background: none; border: none; color: #555; filter: invert(40%); /* gray tint to match font */ } .add-note-btn, .export-import button { margin: 5px; padding: 8px 16px; /* Reduced button size */ font-size: 14px; /* Reduced font size */ border: none; border-radius: 5px; cursor: pointer; background-color: #4CAF50; color: white; } .date-time { position: absolute; top: 10px; right: 40px; /* Adjust to accommodate delete button */ font-size: 0.8em; color: #555; } .delete-button { position: absolute; top: 10px; right: 10px; width: 15px; height: 15px; cursor: pointer; background: none; border: none; color: #555; filter: invert(40%); } .export-import { position: fixed; top: 20px; left: 10px; display: flex; flex-direction: column; gap: 10px; } .color-picker-container { display: grid; grid-template-columns: repeat(4, 1fr); /* 4x4 color palette */ grid-template-rows: repeat(2, 1fr); /* Adjust for 4x4 grid */ gap: 5px; margin-left: 0px; /* Reduced left margin */ margin-top: 20px; } .color-choice { width: 20px; height: 20px; border-radius: 50%; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); } .font-size-control { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; color: #555; } .font-size-control button { background: none; border: none; cursor: pointer; color: #555; font-size: 0.8em; /* Match size with date-time */ } </style> </head> <body> <div class="export-import"> <button class="add-note-btn" onclick="addNote()">Add Note</button> <div class="color-picker-container" id="color-picker-container"> <!-- Pastel color choices --> <div class="color-choice" style="background-color: #FFDDC1;" onclick="selectColor('#FFDDC1')"></div> <div class="color-choice" style="background-color: #FFCCD2;" onclick="selectColor('#FFCCD2')"></div> <div class="color-choice" style="background-color: #D5AAFF;" onclick="selectColor('#D5AAFF')"></div> <div class="color-choice" style="background-color: #C1E1FF;" onclick="selectColor('#C1E1FF')"></div> <div class="color-choice" style="background-color: #C1FFC1;" onclick="selectColor('#C1FFC1')"></div> <div class="color-choice" style="background-color: #FFFFD1;" onclick="selectColor('#FFFFD1')"></div> <div class="color-choice" style="background-color: #D1FFF2;" onclick="selectColor('#D1FFF2')"></div> </div> <button onclick="exportNotes()">Export</button> <input type="file" id="importFile" onchange="importNotes()" style="display: none;"> <button onclick="document.getElementById('importFile').click()">Import</button> </div> <div id="notes-container" class="notes-container"></div> <script> let selectedColor = '#FFFFD1'; // pastel yellow default color function addNote() { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const toolbar = document.createElement('div'); toolbar.className = 'toolbar'; toolbar.innerHTML = ` <button onclick="document.execCommand('bold', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/bold.png" alt="Bold" title="Bold"> </button> <button onclick="document.execCommand('italic', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/italic.png" alt="Italic" title="Italic"> </button> <button onclick="document.execCommand('underline', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/underline.png" alt="Underline" title="Underline"> </button> <button onclick="document.execCommand('insertUnorderedList', false, '')"> <img src="https://img.icons8.com/ios-filled/50/000000/bullet-list.png" alt="Bullet List" title="Bullet List"> </button> `; note.appendChild(toolbar); const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.style.outline = 'none'; content.style.wordWrap = 'break-word'; // Make sure the text wraps note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; const now = new Date(); const formattedDate = now.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }); const formattedTime = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', hour12: true }); dateTime.textContent = `${formattedDate} ${formattedTime}`; note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = ` <img src="https://img.icons8.com/ios-filled/50/000000/trash.png" alt="Delete" title="Delete"> `; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } function selectColor(color) { selectedColor = color || '#FFFFD1'; // default to pastel yellow } function deleteNote(button) { const note = button.closest('.note'); note.remove(); } function changeFontSize(button, action) { const note = button.closest('.note'); const content = note.querySelector('[contenteditable="true"]'); const currentSize = parseFloat(window.getComputedStyle(content).fontSize); if (action === 'increase') { content.style.fontSize = (currentSize + 1) + 'px'; } else if (action === 'decrease') { content.style.fontSize = (currentSize - 1) + 'px'; } } function exportNotes() { let notesData = ''; const notes = document.querySelectorAll('.note'); notes.forEach(note => { const dateTime = note.querySelector('.date-time').textContent; const text = note.querySelector('[contenteditable="true"]').innerHTML; notesData += `Date/Time: ${dateTime}\n${text.replace(/<[^>]*>/g, '')}\n\n---\n\n`; }); const blob = new Blob([notesData], { type: 'text/plain' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'notes.txt'; a.click(); } function importNotes() { const fileInput = document.getElementById('importFile'); const file = fileInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (e) { const content = e.target.result; const notesData = content.split('\n\n---\n\n'); notesData.forEach(noteSection => { const [header, ...textArray] = noteSection.split('\n'); const text = textArray.join('\n').trim(); if (text) { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.innerHTML = text.replace(/(?:\r\n|\r|\n)/g, '<br>'); note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; dateTime.textContent = header.replace('Date/Time: ', ''); note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = ` <img src="https://img.icons8.com/ios-filled/50/000000/trash.png" alt="Delete" title="Delete"> `; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } }); }; reader.readAsText(file); } } </script> </body> </html>Changes Made:
- Replaced
textareawith adivthat usescontenteditable="true"to allow rich text editing (bold, italic, underline). - Added a bullet point feature using the
insertUnorderedListcommand. - Set the delete button size to be the same as the other text feature buttons.
- Added a top margin to the
.notes-containerto prevent the notes from obscuring the buttons at the top.
These adjustments should fix the functionality issues and maintain the theme as requested.
- To make the text formatting (bold, italic, underline) work in a
- User
all icon button should be same as Microsoft word
- Assistant
To make the toolbar icons similar to those used in Microsoft Word, we’ll need to use commonly recognized icons that represent the same functions: Bold, Italic, Underline, Bullet Points, and a Delete (which is not in Word but for your interface). You can use an icon set such as Font Awesome for web-based icons, or equivalent images.
Here's how you can integrate Font Awesome icons for a more professional look:
- Add Font Awesome CDN link to the
<head>of your HTML for loading the icon fonts. - Replace image icons in the toolbar with Font Awesome icon classes.
Here's the updated code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sticky Notes</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <style> body { font-family: Arial, sans-serif; background-color: #f9f9f9; margin: 0; padding: 0; } .notes-container { display: flex; flex-wrap: wrap; justify-content: flex-start; /* Align notes from the left side */ margin: auto; padding: 20px; width: 100%; margin-top: 150px; /* Add top margin to avoid overlap */ } .note { margin: 20px; padding: 60px 20px 20px 20px; border-radius: 5px 5px 5px 20px; /* folder-like shape */ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); width: 240px; position: relative; overflow: hidden; background-color: #FFFFD1; /* pastel yellow default color */ min-height: 150px; } .note [contenteditable="true"] { width: 100%; height: calc(100% - 70px); /* Adjusts to fill available space minus padding */ overflow-y: auto; outline: none; border: none; background: transparent; font-family: inherit; } .toolbar { position: absolute; top: 10px; left: 10px; display: flex; gap: 10px; /* Space between toolbar buttons */ } .toolbar button { width: 20px; height: 20px; cursor: pointer; background: none; border: none; color: #555; font-size: 1em; line-height: 1; } .add-note-btn, .export-import button { margin: 5px; padding: 8px 16px; /* Reduced button size */ font-size: 14px; /* Reduced font size */ border: none; border-radius: 5px; cursor: pointer; background-color: #4CAF50; color: white; } .date-time { position: absolute; top: 10px; right: 40px; /* Adjust to accommodate delete button */ font-size: 0.8em; color: #555; } .delete-button { position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; cursor: pointer; background: none; border: none; color: #555; font-size: 1em; line-height: 1; } .export-import { position: fixed; top: 20px; left: 10px; display: flex; flex-direction: column; gap: 10px; } .color-picker-container { display: grid; grid-template-columns: repeat(4, 1fr); /* 4x4 color palette */ grid-template-rows: repeat(2, 1fr); /* Adjust for 4x4 grid */ gap: 5px; margin-left: 0px; /* Reduced left margin */ margin-top: 20px; } .color-choice { width: 20px; height: 20px; border-radius: 50%; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); } .font-size-control { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; color: #555; } .font-size-control button { background: none; border: none; cursor: pointer; color: #555; font-size: 0.8em; /* Match size with date-time */ } </style> </head> <body> <div class="export-import"> <button class="add-note-btn" onclick="addNote()">Add Note</button> <div class="color-picker-container" id="color-picker-container"> <!-- Pastel color choices --> <div class="color-choice" style="background-color: #FFDDC1;" onclick="selectColor('#FFDDC1')"></div> <div class="color-choice" style="background-color: #FFCCD2;" onclick="selectColor('#FFCCD2')"></div> <div class="color-choice" style="background-color: #D5AAFF;" onclick="selectColor('#D5AAFF')"></div> <div class="color-choice" style="background-color: #C1E1FF;" onclick="selectColor('#C1E1FF')"></div> <div class="color-choice" style="background-color: #C1FFC1;" onclick="selectColor('#C1FFC1')"></div> <div class="color-choice" style="background-color: #FFFFD1;" onclick="selectColor('#FFFFD1')"></div> <div class="color-choice" style="background-color: #D1FFF2;" onclick="selectColor('#D1FFF2')"></div> </div> <button onclick="exportNotes()">Export</button> <input type="file" id="importFile" onchange="importNotes()" style="display: none;"> <button onclick="document.getElementById('importFile').click()">Import</button> </div> <div id="notes-container" class="notes-container"></div> <script> let selectedColor = '#FFFFD1'; // pastel yellow default color function addNote() { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const toolbar = document.createElement('div'); toolbar.className = 'toolbar'; toolbar.innerHTML = ` <button onclick="document.execCommand('bold', false, '')"> <i class="fas fa-bold" title="Bold"></i> </button> <button onclick="document.execCommand('italic', false, '')"> <i class="fas fa-italic" title="Italic"></i> </button> <button onclick="document.execCommand('underline', false, '')"> <i class="fas fa-underline" title="Underline"></i> </button> <button onclick="document.execCommand('insertUnorderedList', false, '')"> <i class="fas fa-list-ul" title="Bullet List"></i> </button> `; note.appendChild(toolbar); const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.style.outline = 'none'; content.style.wordWrap = 'break-word'; // Make sure the text wraps note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; const now = new Date(); const formattedDate = now.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }); const formattedTime = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', hour12: true }); dateTime.textContent = `${formattedDate} ${formattedTime}`; note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = `<i class="fas fa-trash" title="Delete"></i>`; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } function selectColor(color) { selectedColor = color || '#FFFFD1'; // default to pastel yellow } function deleteNote(button) { const note = button.closest('.note'); note.remove(); } function changeFontSize(button, action) { const note = button.closest('.note'); const content = note.querySelector('[contenteditable="true"]'); const currentSize = parseFloat(window.getComputedStyle(content).fontSize); if (action === 'increase') { content.style.fontSize = (currentSize + 1) + 'px'; } else if (action === 'decrease') { content.style.fontSize = (currentSize - 1) + 'px'; } } function exportNotes() { let notesData = ''; const notes = document.querySelectorAll('.note'); notes.forEach(note => { const dateTime = note.querySelector('.date-time').textContent; const text = note.querySelector('[contenteditable="true"]').innerHTML; notesData += `Date/Time: ${dateTime}\n${text.replace(/<[^>]*>/g, '')}\n\n---\n\n`; }); const blob = new Blob([notesData], { type: 'text/plain' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'notes.txt'; a.click(); } function importNotes() { const fileInput = document.getElementById('importFile'); const file = fileInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (e) { const content = e.target.result; const notesData = content.split('\n\n---\n\n'); notesData.forEach(noteSection => { const [header, ...textArray] = noteSection.split('\n'); const text = textArray.join('\n').trim(); if (text) { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.innerHTML = text.replace(/(?:\r\n|\r|\n)/g, '<br>'); note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; dateTime.textContent = header.replace('Date/Time: ', ''); note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = `<i class="fas fa-trash" title="Delete"></i>`; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } }); }; reader.readAsText(file); } } </script> </body> </html>Summary of Changes:
- Font Awesome: Added the Font Awesome CDN for professional icon use.
- Toolbar Icons: Replaced toolbar icons with Font Awesome classes (
fa-bold,fa-italic,fa-underline,fa-list-ul, andfa-trash). - Button Sizing: Consistency in size and appearance for all toolbar buttons has been ensured.
This should maintain the theme and improve user experience by using recognizable icons, similar to those found in Microsoft Word.
- Add Font Awesome CDN link to the
- User
great job, just do little more changes as i suggest below
- put margin from left where buttons end not from top.
- increse the width of notes.
- Assistant
Certainly! Let's make those adjustments:
- Adjust the margin from the left where the buttons end, rather than the default top margin.
- Increase the width of the sticky notes for more content space.
Here's the updated code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sticky Notes</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <style> body { font-family: Arial, sans-serif; background-color: #f9f9f9; margin: 0; padding: 0; } .notes-container { display: flex; flex-wrap: wrap; justify-content: flex-start; /* Align notes from the left side */ padding: 20px; width: 100%; margin-left: 150px; /* Add left margin to avoid overlap with buttons */ } .note { margin: 20px; padding: 60px 20px 20px 20px; border-radius: 5px 5px 5px 20px; /* folder-like shape */ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); width: 300px; /* Increased width for more content space */ position: relative; overflow: hidden; background-color: #FFFFD1; /* pastel yellow default color */ min-height: 150px; } .note [contenteditable="true"] { width: 100%; height: calc(100% - 70px); /* Adjusts to fill available space minus padding */ overflow-y: auto; outline: none; border: none; background: transparent; font-family: inherit; } .toolbar { position: absolute; top: 10px; left: 10px; display: flex; gap: 10px; /* Space between toolbar buttons */ } .toolbar button { width: 20px; height: 20px; cursor: pointer; background: none; border: none; color: #555; font-size: 1em; line-height: 1; } .add-note-btn, .export-import button { margin: 5px; padding: 8px 16px; /* Reduced button size */ font-size: 14px; /* Reduced font size */ border: none; border-radius: 5px; cursor: pointer; background-color: #4CAF50; color: white; } .date-time { position: absolute; top: 10px; right: 40px; /* Adjust to accommodate delete button */ font-size: 0.8em; color: #555; } .delete-button { position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; cursor: pointer; background: none; border: none; color: #555; font-size: 1em; line-height: 1; } .export-import { position: fixed; top: 20px; left: 20px; display: flex; flex-direction: column; gap: 10px; } .color-picker-container { display: grid; grid-template-columns: repeat(4, 1fr); /* 4x4 color palette */ grid-template-rows: repeat(2, 1fr); /* Adjust for 4x4 grid */ gap: 5px; margin-left: 0px; /* Reduced left margin */ margin-top: 20px; } .color-choice { width: 20px; height: 20px; border-radius: 50%; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); } .font-size-control { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; color: #555; } .font-size-control button { background: none; border: none; cursor: pointer; color: #555; font-size: 0.8em; /* Match size with date-time */ } </style> </head> <body> <div class="export-import"> <button class="add-note-btn" onclick="addNote()">Add Note</button> <div class="color-picker-container" id="color-picker-container"> <!-- Pastel color choices --> <div class="color-choice" style="background-color: #FFDDC1;" onclick="selectColor('#FFDDC1')"></div> <div class="color-choice" style="background-color: #FFCCD2;" onclick="selectColor('#FFCCD2')"></div> <div class="color-choice" style="background-color: #D5AAFF;" onclick="selectColor('#D5AAFF')"></div> <div class="color-choice" style="background-color: #C1E1FF;" onclick="selectColor('#C1E1FF')"></div> <div class="color-choice" style="background-color: #C1FFC1;" onclick="selectColor('#C1FFC1')"></div> <div class="color-choice" style="background-color: #FFFFD1;" onclick="selectColor('#FFFFD1')"></div> <div class="color-choice" style="background-color: #D1FFF2;" onclick="selectColor('#D1FFF2')"></div> </div> <button onclick="exportNotes()">Export</button> <input type="file" id="importFile" onchange="importNotes()" style="display: none;"> <button onclick="document.getElementById('importFile').click()">Import</button> </div> <div id="notes-container" class="notes-container"></div> <script> let selectedColor = '#FFFFD1'; // pastel yellow default color function addNote() { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const toolbar = document.createElement('div'); toolbar.className = 'toolbar'; toolbar.innerHTML = ` <button onclick="document.execCommand('bold', false, '')"> <i class="fas fa-bold" title="Bold"></i> </button> <button onclick="document.execCommand('italic', false, '')"> <i class="fas fa-italic" title="Italic"></i> </button> <button onclick="document.execCommand('underline', false, '')"> <i class="fas fa-underline" title="Underline"></i> </button> <button onclick="document.execCommand('insertUnorderedList', false, '')"> <i class="fas fa-list-ul" title="Bullet List"></i> </button> `; note.appendChild(toolbar); const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.style.outline = 'none'; content.style.wordWrap = 'break-word'; // Make sure the text wraps note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; const now = new Date(); const formattedDate = now.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }); const formattedTime = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', hour12: true }); dateTime.textContent = `${formattedDate} ${formattedTime}`; note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = `<i class="fas fa-trash" title="Delete"></i>`; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } function selectColor(color) { selectedColor = color || '#FFFFD1'; // default to pastel yellow } function deleteNote(button) { const note = button.closest('.note'); note.remove(); } function changeFontSize(button, action) { const note = button.closest('.note'); const content = note.querySelector('[contenteditable="true"]'); const currentSize = parseFloat(window.getComputedStyle(content).fontSize); if (action === 'increase') { content.style.fontSize = (currentSize + 1) + 'px'; } else if (action === 'decrease') { content.style.fontSize = (currentSize - 1) + 'px'; } } function exportNotes() { let notesData = ''; const notes = document.querySelectorAll('.note'); notes.forEach(note => { const dateTime = note.querySelector('.date-time').textContent; const text = note.querySelector('[contenteditable="true"]').innerHTML; notesData += `Date/Time: ${dateTime}\n${text.replace(/<[^>]*>/g, '')}\n\n---\n\n`; }); const blob = new Blob([notesData], { type: 'text/plain' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'notes.txt'; a.click(); } function importNotes() { const fileInput = document.getElementById('importFile'); const file = fileInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (e) { const content = e.target.result; const notesData = content.split('\n\n---\n\n'); notesData.forEach(noteSection => { const [header, ...textArray] = noteSection.split('\n'); const text = textArray.join('\n').trim(); if (text) { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.innerHTML = text.replace(/(?:\r\n|\r|\n)/g, '<br>'); note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; dateTime.textContent = header.replace('Date/Time: ', ''); note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = `<i class="fas fa-trash" title="Delete"></i>`; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } }); }; reader.readAsText(file); } } </script> </body> </html>Summary of Changes:
- Margin Adjustment: Added a left margin of
150pxto the.notes-containerto accommodate the button panel, ensuring that notes do not overlap with the button section. - Note Width Increased: Adjusted the width of each note to
300pxto provide more space for content.
These adjustments should maintain the overall design while incorporating your required changes.
- User
nice but need little more improvements.
1 it should fit on one page in width 2 manual size change option for each note and should work separately 3 whenever i slide page it should not hover, it should be fixed but never cover my left buttons. 4 also remove the curve from notes add double line below text features.
- Assistant
To address your requests, let's make the following improvements:
- Ensure the notes fit within the page's width, accommodating multiple notes based on the viewport size.
- Add the ability to resize each note manually.
- Allow notes to be scrolled but ensure that they do not overlap the left-side buttons, which will remain fixed.
- Remove the curve from the top border of the notes and add a double-line divider beneath the toolbar.
Here's the updated code to implement these changes:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sticky Notes</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> <style> body { font-family: Arial, sans-serif; background-color: #f9f9f9; margin: 0; padding: 0; display: flex; } .export-import { position: fixed; top: 20px; left: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 1000; } .notes-container { display: flex; flex-wrap: wrap; justify-content: flex-start; padding: 20px; margin-left: 150px; margin-top: 0; width: calc(100% - 170px); /* Account for left margin */ overflow-y: auto; height: 100vh; box-sizing: border-box; } .note { margin: 10px; padding: 40px 20px 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); width: 300px; background-color: #FFFFD1; min-height: 150px; max-width: 100%; /* Ensure it doesn't exceed container's width */ position: relative; resize: both; /* Enable manual resizing */ overflow: auto; } .note [contenteditable="true"] { width: 100%; height: calc(100% - 80px); /* Adjusts to fill available space minus paddings */ overflow-y: auto; outline: none; border: none; background: transparent; font-family: inherit; } .toolbar { position: absolute; top: 10px; left: 10px; display: flex; gap: 10px; width: calc(100% - 20px); border-bottom: 2px double #555; /* Double line below toolbar */ } .toolbar button { width: 20px; height: 20px; cursor: pointer; background: none; border: none; color: #555; font-size: 1em; line-height: 1; } .add-note-btn, .export-import button { margin: 5px; padding: 8px 16px; font-size: 14px; border: none; border-radius: 5px; cursor: pointer; background-color: #4CAF50; color: white; } .date-time { position: absolute; top: 10px; right: 40px; font-size: 0.8em; color: #555; } .delete-button { position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; cursor: pointer; background: none; border: none; color: #555; font-size: 1em; line-height: 1; } .color-picker-container { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr); gap: 5px; margin-left: 0px; margin-top: 20px; } .color-choice { width: 20px; height: 20px; border-radius: 50%; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2); } .font-size-control { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); display: flex; flex-direction: column; gap: 2px; color: #555; } .font-size-control button { background: none; border: none; cursor: pointer; color: #555; font-size: 0.8em; } </style> </head> <body> <div class="export-import"> <button class="add-note-btn" onclick="addNote()">Add Note</button> <div class="color-picker-container" id="color-picker-container"> <div class="color-choice" style="background-color: #FFDDC1;" onclick="selectColor('#FFDDC1')"></div> <div class="color-choice" style="background-color: #FFCCD2;" onclick="selectColor('#FFCCD2')"></div> <div class="color-choice" style="background-color: #D5AAFF;" onclick="selectColor('#D5AAFF')"></div> <div class="color-choice" style="background-color: #C1E1FF;" onclick="selectColor('#C1E1FF')"></div> <div class="color-choice" style="background-color: #C1FFC1;" onclick="selectColor('#C1FFC1')"></div> <div class="color-choice" style="background-color: #FFFFD1;" onclick="selectColor('#FFFFD1')"></div> <div class="color-choice" style="background-color: #D1FFF2;" onclick="selectColor('#D1FFF2')"></div> </div> <button onclick="exportNotes()">Export</button> <input type="file" id="importFile" onchange="importNotes()" style="display: none;"> <button onclick="document.getElementById('importFile').click()">Import</button> </div> <div id="notes-container" class="notes-container"></div> <script> let selectedColor = '#FFFFD1'; // pastel yellow default color function addNote() { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const toolbar = document.createElement('div'); toolbar.className = 'toolbar'; toolbar.innerHTML = ` <button onclick="document.execCommand('bold', false, '')"> <i class="fas fa-bold" title="Bold"></i> </button> <button onclick="document.execCommand('italic', false, '')"> <i class="fas fa-italic" title="Italic"></i> </button> <button onclick="document.execCommand('underline', false, '')"> <i class="fas fa-underline" title="Underline"></i> </button> <button onclick="document.execCommand('insertUnorderedList', false, '')"> <i class="fas fa-list-ul" title="Bullet List"></i> </button> `; note.appendChild(toolbar); const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.style.outline = 'none'; content.style.wordWrap = 'break-word'; note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; const now = new Date(); const formattedDate = now.toLocaleDateString('en-GB', { day: '2-digit', month: '2-digit', year: 'numeric' }); const formattedTime = now.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit', hour12: true }); dateTime.textContent = `${formattedDate} ${formattedTime}`; note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = `<i class="fas fa-trash" title="Delete"></i>`; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } function selectColor(color) { selectedColor = color || '#FFFFD1'; // default to pastel yellow } function deleteNote(button) { const note = button.closest('.note'); note.remove(); } function changeFontSize(button, action) { const note = button.closest('.note'); const content = note.querySelector('[contenteditable="true"]'); const currentSize = parseFloat(window.getComputedStyle(content).fontSize); if (action === 'increase') { content.style.fontSize = (currentSize + 1) + 'px'; } else if (action === 'decrease') { content.style.fontSize = (currentSize - 1) + 'px'; } } function exportNotes() { let notesData = ''; const notes = document.querySelectorAll('.note'); notes.forEach(note => { const dateTime = note.querySelector('.date-time').textContent; const text = note.querySelector('[contenteditable="true"]').innerHTML; notesData += `Date/Time: ${dateTime}\n${text.replace(/<[^>]*>/g, '')}\n\n---\n\n`; }); const blob = new Blob([notesData], { type: 'text/plain' }); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'notes.txt'; a.click(); } function importNotes() { const fileInput = document.getElementById('importFile'); const file = fileInput.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (e) { const content = e.target.result; const notesData = content.split('\n\n---\n\n'); notesData.forEach(noteSection => { const [header, ...textArray] = noteSection.split('\n'); const text = textArray.join('\n').trim(); if (text) { const noteContainer = document.getElementById('notes-container'); const note = document.createElement('div'); note.className = 'note'; note.style.backgroundColor = selectedColor; const content = document.createElement('div'); content.contentEditable = true; content.style.minHeight = '100px'; content.innerHTML = text.replace(/(?:\r\n|\r|\n)/g, '<br>'); note.appendChild(content); const dateTime = document.createElement('div'); dateTime.className = 'date-time'; dateTime.textContent = header.replace('Date/Time: ', ''); note.appendChild(dateTime); const deleteButton = document.createElement('button'); deleteButton.className = 'delete-button'; deleteButton.innerHTML = `<i class="fas fa-trash" title="Delete"></i>`; deleteButton.onclick = function () { deleteNote(deleteButton); }; note.appendChild(deleteButton); const fontSizeControl = document.createElement('div'); fontSizeControl.className = 'font-size-control'; fontSizeControl.innerHTML = ` <button onclick="changeFontSize(this, 'increase')">+</button> <button onclick="changeFontSize(this, 'decrease')">-</button> `; note.appendChild(fontSizeControl); noteContainer.appendChild(note); } }); }; reader.readAsText(file); } } </script> </body> </html>Summary of Changes:
- Flexible Layout: The
.notes-containernow accommodates the full width of the page minus the fixed-width space for buttons, allowing notes to fit within the viewport. - Manual Resizing: Notes can now be resized individually using the
resizeproperty. - Fixed Left Panel: The left panel with buttons is fixed and will remain visible while scrolling through notes.
- Double Line Divider: A double-line divider is added below the toolbar.
- Straight Borders: Removed rounded corners to provide a straight, modern look.
These changes should work together to meet your requirements while maintaining a cohesive interface.