Struggling to center text inside a textarea within a flexbox nested in a grid? Despite my efforts, I can't seem to crack it. Here's the Fiddle code snippet:
// Attempting to Center Text
const myDocumentAreaFiltersGlobalDisplay = document.getElementById("document_area_filters_global_display_id")
const myFiltersGlobalDisplayWrap = document.createElement("div");
myFiltersGlobalDisplayWrap.classList.add("myFiltersGlobalDisplayWrap");
// Creating TextArea Element
const myFiltersGlobalDisplay = document.createElement("textarea");
myFiltersGlobalDisplay.classList.add("myFiltersGlobalDisplay");
myFiltersGlobalDisplay.value = "CENTER ME PLEASE";
// Adding Reset Button
myFilterGlobalResetButton = document.createElement("button");
myFilterGlobalResetButton.textContent = "X";
myFiltersGlobalDisplayWrap.appendChild(myFiltersGlobalDisplay);
myFiltersGlobalDisplayWrap.appendChild(myFilterGlobalResetButton);
myDocumentAreaFiltersGlobalDisplay.appendChild(myFiltersGlobalDisplayWrap);
/* Styling for Grid Layout */
.document_grid {
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr;
gap: 0px;
grid-template-areas:
"document_area_filters_global_display";
}
html,
body,
.document_grid {
height: 100%;
margin: 0;
}
textarea {
border: 1 px solid grey;
resize: none;
width: 100%;
padding-top: 0px;
padding-bottom: 0px;
overflow: hidden;
}
.myFiltersGlobalDisplayWrap{
display: flex;
flex-direction: row;
align-items: center;
}
.myFiltersGlobalDisplay{
line-height: 1;
text-align: right;
padding-right: 5px;
}
<div class="document_area_filters_global_display" id="document_area_filters_global_display_id"></div>
The goal is to set the textarea height to one line of text and ensure the button on the right matches the same height as the textarea.