Is there a way to set the text overflow to visible without scroll bars in dynamically added <div>
s?
Despite what the documentation says, it doesn't seem to be the default behavior and I'm struggling to understand why.
Adding text directly to the <div>
or within a child <p>
element doesn't change the output.
If you'd like to see a demo, check out this link on CodePen.
Here's the code snippet from the CodePen:
let container = document.querySelector("#container");
let string = "HELLO WORLD!";
for (row = 0; row < 11; row++) {
for (col = 0; col < 16; col++) {
let tile = document.createElement("div");
container.appendChild(tile);
$(tile).addClass("tile");
if (row == 5 && col > 1 && col < 14) {
let p = document.createElement("p");
tile.appendChild(p);
$(p).addClass("letter");
$(p).text(string[col - 2]);
}
}
}
:root {
--tileWidth: 30px;
}
.container {
display: grid;
grid-template-columns: var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth) var(--tileWidth);
}
.tile {
display: block;
width: var(--tileWidth);
height: var(--tileWidth);
position: relative;
background-color: teal;
font-size: calc(var(--tileWidth)*2);
color: tomato;
padding: 0;
text-align: center;
font-family: Impact;
}
.letter {
overflow: visible visible;
margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="container" class="container"></div>