JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="notepad">
<div class="add-button">
<input type="text" class="topic" value="Заголовок">
<input type="text" class="description" value="Описание">
Добавить
</div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
* {
margin: 0px; padding: 0px; color: white; text-align: center;
}
.notepad {
width: 500px;
height: 800px;
background-color: #8FC2E9;
margin: 50px auto;
position: relative;
}
.note {
width: 450px;
height: 50px;
background-color: #3F92D2;
margin: 20px auto;
position: relative;
}
.note-description {
width: 450px;
height: 150px;
background-color: #66A3D2;
margin: auto;
position: absolute;
top: 100%;
z-index: 1;
}
.delete-button {
width: 10px;
height: 10px;
background-color: #BF3030;
position: absolute;
top: 10px; right: 10px;
border-radius: 100%;
z-index: 1;
}
.hide {
display: none;
}
.add-button {
width: 450px;
height: 100px;
background-color: #215C89;
margin: auto;
position: absolute;
bottom: 20px; left: 25px;
}
.topic {
width: 100%;
height: 25px;
border: none;
background-color: #A7CCE9;
}
.description {
width: 100%;
height: 50px;
border: none;
background-color: rgb(192, 214, 231);
}
JavaScript
var notepad = document.querySelector('.notepad');
var topic = document.querySelector('.topic');
var description = document.querySelector('.description');
var noteQty = 0;
notepad.addEventListener('click', function(event) {
console.log(event.target);
if (event.target.classList == 'add-button' && noteQty != 9) {
var note = document.createElement('div');
note.classList.add('note');
note.textContent = topic.value;
topic.value = '';
var noteDescription = document.createElement('div');
noteDescription.classList.add('note-description', 'hide');
noteDescription.textContent = description.value;
description.value = '';
var deleteButton = document.createElement('div');
deleteButton.classList.add('delete-button', 'hide')
deleteButton.addEventListener('click', function() {
note.style.display = 'none';
noteQty--;
})
note.insertAdjacentElement('afterbegin', noteDescription);
note.insertAdjacentElement('afterbegin', deleteButton);
note.addEventListener('mouseenter', function() {
noteDescription.classList.remove('hide');
deleteButton.classList.remove('hide');
})
note.addEventListener('mouseleave', function() {
noteDescription.classList.add('hide');
deleteButton.classList.add('hide');
})
notepad.insertAdjacentElement('afterbegin', note);
noteQty++;
}
})