Answer the question
In order to leave comments, you need to log in
How to display php code inline using flexbox?
I can’t display items in a line with transfer to another,
I write code
<?php foreach ($latestProducts as $product): ?>
<div class="container-flex">
<div class="item">
<h2><?php echo $product['id'];?></h2>
<p>
<a href="/product/<?php echo $product['id'];?>">
<?php echo $product['name'];?>
</a>
</p>
<a href="#"">Посмотреть</a>
</div>
<?php endforeach;?>
</div>
.container-flex {
min-height: 400px;
display: flex;
display: -webkit-flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: flex-start;
align-items: flex-start;
align-content: stretch;
}
.item {
flex: 0 0 0;
margin: 5px;
}
Answer the question
In order to leave comments, you need to log in
Move flex container outside the loop
<div class="container-flex">
<?php foreach ($latestProducts as $product): ?>
<div class="item">
<h2>
<?php echo $product['id'];?>
</h2>
<p>
<a href="/product/<?php echo $product['id'];?>">
<?php echo $product['name'];?>
</a>
</p>
<a href="#">Посмотреть</a>
</div>
<?php endforeach; ?>
</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question