<header>
<h2 class="title">element.style.unicodeBidi</h2>
<p class="description">Змінює порядок відображення тексту для підтримки двонаправленого тексту.</p>
</header>
<main>
<div class="result">
<!-- Форма для вибору напрямку тексту -->
<form id="directionForm">
<label for="directionLtr">
<input type="radio" id="directionLtr" name="direction" value="ltr" checked>
Ліворуч-праворуч (LTR)
</label>
<label for="directionRtl">
<input type="radio" id="directionRtl" name="direction" value="rtl">
Праворуч-ліворуч (RTL)
</label>
</form>
<!-- Елемент для відображення тексту -->
<div id="textElement">
Текст буде змінювати свій напрямок в залежності від вибору користувача.
</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);
}
#textElement {
margin-top: 15px;
padding: 10px;
background-color: #fff;
border: 1px solid #ddd;
}
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('directionForm');
const textElement = document.getElementById('textElement');
form.addEventListener('change', function(event) {
const direction = event.target.value;
if (direction === 'rtl') {
textElement.style.direction = 'rtl';
textElement.style.unicodeBidi = 'embed';
} else {
textElement.style.direction = 'ltr';
textElement.style.unicodeBidi = 'embed';
}
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.