<header>
<h2 class="title">element.style.right</h2>
<p class="description">Встановлює або повертає правий відступ елемента від його найближчого розташованого предка.</p>
</header>
<main>
<div class="result">
<div id="movableElement" class="movable">Переміщуй мене</div>
<div>
<button id="moveLeftButton">Перемістити ліворуч</button>
<button id="moveRightButton">Перемістити праворуч</button>
</div>
</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);
}
.movable {
position: fixed;
top: 50px;
right: 50px;
width: 150px;
height: 50px;
background-color: #4CAF50;
color: white;
display: flex;
align-items: center;
justify-content: center;
border-radius: 5px;
}
button {
margin: 10px 5px;
padding: 10px 20px;
background-color: #008CBA;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #005f6b;
}
const movableElement = document.getElementById('movableElement');
const moveLeftButton = document.getElementById('moveLeftButton');
const moveRightButton = document.getElementById('moveRightButton');
moveLeftButton.addEventListener('click', function() {
let currentRight = parseInt(movableElement.style.right);
if (isNaN(currentRight)) {
currentRight = 50; // Початкове значення, якщо відсутнє
}
movableElement.style.right = (currentRight + 10) + 'px';
});
moveRightButton.addEventListener('click', function() {
let currentRight = parseInt(movableElement.style.right);
if (isNaN(currentRight)) {
currentRight = 50; // Початкове значення, якщо відсутнє
}
movableElement.style.right = (currentRight - 10) + 'px';
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.