简体   繁体   English

使用while循环时如何将文本放在图像旁边,并且每次迭代都会添加其他组件

[英]How to put text next to images when using while loop and additional components are being added on each iteration

I want to display an image to the right of my text.我想在文本右侧显示图像。

I currently have code that does that but as the while loop iterates it keeps on adding the text and image to the right of the original one.我目前有执行此操作的代码,但是随着 while 循环的迭代,它不断将文本和图像添加到原始循环的右侧。

I am using php so I am echoing everything.我正在使用 php 所以我正在呼应一切。

How do I make it so it works like this:我如何使它像这样工作:

text image
text image
text image
text image 
text image

Here is my code:这是我的代码:

code代码

One solution could be to use flexbox and add the styles 'display: flex;一种解决方案是使用 flexbox 并添加 styles 'display: flex; flex-wrap: wrap;'弹性包装:包装;' to the parent div到父 div

 <div style='display:flex; flex-wrap:wrap;'> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text</p> <p style='float:left;'>image</p> </div> <div style='display:flex; flex-wrap:wrap;'> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text</p> <p style='float:left;'>image</p> </div> <div style='display:flex; flex-wrap:wrap;'> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text</p> <p style='float:left;'>image</p> </div>

To make them flow to the next column when exceeding the height, instead of putting display: flex;让它们在超过高度时流到下一列,而不是放置 display: flex; and flex-wrap: wrap;和 flex-wrap: 换行; on each individual div, wrap all of the divs with a parent container and add display flex, flex wrap, and flex direction column to the parent.在每个单独的 div 上,使用父容器包装所有 div,并将显示 flex、flex wrap 和 flex 方向列添加到父容器。 Make sure to specify a height.确保指定高度。

What this does is arrange each child element in a column and when they reach the bottom of the parent div, it will wrap into the next column.这样做是将每个子元素排列在一列中,当它们到达父 div 的底部时,它将换行到下一列。 You can look more into flexbox to see how you can further arrange the columns if needed.您可以深入了解 flexbox 以了解如何在需要时进一步排列列。 Hope this helps!希望这可以帮助!

 <div style='display:flex; flex-direction:column; flex-wrap:wrap; height: 200px; background:#ccc;'> <div> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text1</p> <p style='float:left;'>image</p> </div> <div> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text2</p> <p style='float:left;'>image</p> </div> <div> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text3</p> <p style='float:left;'>image</p> </div> <div> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text4</p> <p style='float:left;'>image</p> </div> <div> <p style='font-size:1.05em; color=#0e3c68; font-weight:bold; float:left;'>text5</p> <p style='float:left;'>image</p> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 while 循环创建文本字段时,如何将多个文本字段值发送到下一个 pho 页面? - How to send multiple text field values to next pho page when the text field is created using while loop? 使用while循环时,如何获取每个输入文本的单独值? - How can I get the individual value of each input text when I am using a while loop? 如何在while循环的每次迭代中发送不同的会话数组? - How to send a different Session Array each iteration of a while loop? 在每次for循环迭代中覆盖数组 - Array being overriden at each iteration of for loop 如何从mysqli查询中将文本并排放置 - How to put text next to each other from mysqli query PHP foreach堆栈-在调用下一次迭代时,是否可能在每个循环中调用的函数仍在运行 - PHP foreach stack - is it possible that functions called in a for each loop are still running when the next iteration is called 在While循环中为每次迭代运行公共功能 - Running public function for each iteration in a While Loop 如何使用php在数据库中的每个项目旁边放置一个输入框 - how to put an input box next to each item in a database using php 如何在while循环中循环一个按钮,并在每次迭代中为其赋予不同的ID? - How do I loop one button in a while loop and give it different id's in each iteration? 来自foreach循环的彼此相邻的图像 - Images next to each other from a foreach loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM