<header>
<h2 class="title">element.style.objectPosition</h2>
<p class="description">Задає положення елемента всередині контейнера.</p>
</header>
<main>
<div class="result">
<!-- Кнопки для зміни положення текстового блоку -->
<div>
<button id="topLeft">Top Left</button>
<button id="center">Center</button>
<button id="bottomRight">Bottom Right</button>
</div>
<!-- Контейнер з текстовим блоком для демонстрації -->
<div class="text-container">
<div id="demoText" class="text-block">Text Block</div>
</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);
}
.text-container {
width: 400px;
height: 200px;
border: 1px solid #ddd;
position: relative;
overflow: hidden;
}
.text-block {
width: 100px;
height: 50px;
background-color: #4CAF50;
color: white;
display: flex;
align-items: center;
justify-content: center;
object-fit: cover;
object-position: center;
position: absolute;
}
document.addEventListener('DOMContentLoaded', function() {
const demoText = document.getElementById('demoText');
const topLeftButton = document.getElementById('topLeft');
const centerButton = document.getElementById('center');
const bottomRightButton = document.getElementById('bottomRight');
topLeftButton.addEventListener('click', function() {
demoText.style.objectPosition = 'top left';
demoText.style.top = '0';
demoText.style.left = '0';
});
centerButton.addEventListener('click', function() {
demoText.style.objectPosition = 'center';
demoText.style.top = '50%';
demoText.style.left = '50%';
demoText.style.transform = 'translate(-50%, -50%)';
});
bottomRightButton.addEventListener('click', function() {
demoText.style.objectPosition = 'bottom right';
demoText.style.bottom = '0';
demoText.style.right = '0';
demoText.style.top = 'auto';
demoText.style.left = 'auto';
demoText.style.transform = 'none';
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.