<header>
<h2 class="title">element.style.borderWidth</h2>
<p class="description">Дозволяє змінювати ширину всіх чотирьох сторін кордону елемента.</p>
</header>
<main>
<div class="result">
<!-- Елемент, на якому будемо змінювати ширину кордону -->
<div id="demoElement" class="demo-box">Кордон цього елемента змінюється!</div>
<!-- Форма для введення значень ширини кордону -->
<form id="borderForm">
<label for="borderTopWidth">Верхній кордон (px):</label>
<input type="number" id="borderTopWidth" name="borderTopWidth" min="0" value="1">
<br><label for="borderRightWidth">Правий кордон (px):</label>
<input type="number" id="borderRightWidth" name="borderRightWidth" min="0" value="1">
<br><label for="borderBottomWidth">Нижній кордон (px):</label>
<input type="number" id="borderBottomWidth" name="borderBottomWidth" min="0" value="1">
<br><label for="borderLeftWidth">Лівий кордон (px):</label>
<input type="number" id="borderLeftWidth" name="borderLeftWidth" min="0" value="1">
<button type="submit">Застосувати</button>
</form>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
/* Стилі для демонстраційного елемента */
.demo-box {
border: solid black;
border-width: 1px;
padding: 20px;
text-align: center;
margin-bottom: 20px;
}
document.getElementById('borderForm').addEventListener('submit', function(event) {
event.preventDefault(); // Відміна стандартної дії відправки форми
let borderTopWidth = document.getElementById('borderTopWidth').value + 'px';
let borderRightWidth = document.getElementById('borderRightWidth').value + 'px';
let borderBottomWidth = document.getElementById('borderBottomWidth').value + 'px';
let borderLeftWidth = document.getElementById('borderLeftWidth').value + 'px';
let demoElement = document.getElementById('demoElement'); // Отримання елемента для зміни стилю
// Застосування нових значень ширини кордону
demoElement.style.borderTopWidth = borderTopWidth;
demoElement.style.borderRightWidth = borderRightWidth;
demoElement.style.borderBottomWidth = borderBottomWidth;
demoElement.style.borderLeftWidth = borderLeftWidth;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.