Answer the question
In order to leave comments, you need to log in
How to place several other "sub-elements" on a flex grid element?
I am a beginner coder, so such (possibly obvious) questions appear, I would be grateful for an answer or a good resource for solving a similar problem)
I have a task to place cards of some projects with names under them. The problem is that so far it has only been possible to make the text look adequate only in the center of the card, but not below it. Also, there is a problem that if the text is too long, then it wraps to the next line as a new grid item. It looks like this:
Here is the code itself:
HTML
<ul class="flex-container">
<?php foreach($projects as $key): ?>
<?php $url = 'project.php?=' . http_build_query(['id' => $key['id'] ]); ?>
<li class="flex-item" style="<?= $key['image']; ?>"><a href="<?= $url; ?>" style="font-size: 10px; color:white;"><?= $key['name']; ?></a></li>
<?php endforeach; ?>
</ul>
.flex-container {
margin-top: 100px;
padding: 10px;
margin-left:50%;
max-width: 1300px;
display: flex;
flex-flow: row wrap;
justify-content: space-around;
padding: 10px;
font-size: 10px;
margin: 0 -5px;
list-style: none;
}
.flex-item {
padding: 5px;
width: 250px;
height: 220px;
margin-top: 10px;
padding-top: 12%;
line-height: 150px;
color: white;
font-weight: bold;
font-size: 10px;
text-align: center;
}
Answer the question
In order to leave comments, you need to log in
line-height: 150px;
so that the grid adjusts to the text, and not vice versa
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question