I had a grid of squares. Every square has a text inside vertycally centered, but if the text is too long go out of div. I tried with property 'word-wrap: break-word;' inside table-cell class but nothing happens. The size of the div must be the same because later I would like to make the text responsive based on the size of the square.
.table {
height: 100%;
width: 100%;
display: table;
}
.table-cell {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
grid-auto-rows: 1fr;
}
.grid::before {
content: '';
width: 0;
padding-bottom: 100%;
grid-row: 1 / 1;
grid-column: 1 / 1;
}
.grid > *:first-child {
grid-row: 1 / 1;
grid-column: 1 / 1;
}
.grid > * {
background: rgba(0,0,0,0.1);
border: 1px white solid;
}
<div class="grid">
<div id="preview" class="table">
<div id="previewText" class="table-cell">kjfvndkjfvnkdjfvnkdjfvnkjdfjkvndjkfvnjdvfvpensierosdvjsdhkvjsdnvksjd</div>
</div>
</div>