简体   繁体   English

如何正确并排显示两个字符串

[英]How to properly display two strings side by side

I have two arrays which I use implode() on to convert into strings which are then echoed out. 我有两个数组,可以使用implode()转换为字符串,然后将其回显。

Ideally i'd like the 1 value from the one string to be next to the other value in the other string, prefably nested inside a 理想情况下,我希望一个字符串中的1值与另一个字符串中的另一个值相邻,最好嵌套在

<p></p>

Here's the code I'm using to issue a line break after every value, wrap it in a div, and float it. 这是我用来在每个值之后发出换行符,将其包装在div中并进行浮动的代码。

<?php 
echo '<div class="wrapper"><div style="text-align:left; float:left;"         
class="glue">';
echo implode('<br>',$test);
echo '</div>';
echo '<div style="text-align:right; float:right;" class="glue">';
echo implode('<br>',$_POST);
echo '</div></div>';
?>

This works well for now as both divs sit next to each other within my container but it would be easier if the values were inside P tags instead so I could easily put an image in-between them. 现在这很好用,因为两个div在我的容器中彼此并排放置,但是如果值位于P标记内会更容易,那么我可以轻松地在它们之间放置一个图像。

I've added some images below to better demonstrate what I'm going for. 我在下面添加了一些图像,以更好地演示我要做什么。 The first one is what I've tried and the second one is what I would like. 第一个是我尝试过的,第二个是我想要的。

在此处输入图片说明 在此处输入图片说明

That is not possible until you split the paragraph tag into 2 halves. 在将段落标签分成两半之前,这是不可能的。

Try this, 尝试这个,

 .div1 { float: left; } .div2 { float:right; } .div2 { float:right; text-align: right; } 
 <p> <div class="div1">Left Text</div> <div class="div2">Right Text</div> </p> 

Is it what you want? 是你想要的吗?

<style type="text/css">
    p{
        overflow: hidden;
    }
    span.left{
        float: left;
    }
    span.right{
        float: right;
    }
</style>
<?php
foreach($test as $k=>$v){
    echo '<p><span class="left">'.$test[$k].'</span><span class="right">'.$_POST[$k].'</span></p>';
}

if both arrays have the same length the most simple example woud look like this: 如果两个数组的长度相同,则最简单的示例如下所示:

<?php 
$test[0] = "a";
$test[1] = "b";
$test[2] = "c";
$test[3] = "d";
$test2[0] = 1;
$test2[1] = 2;
$test2[2] = 3;
$test2[3] = 4;
for($i=0;$i<count($test);$i++)
{
echo "<p><nobr>".$test[$i] . "</nobr> <nobr style='float:right;'>" . $test2[$i] . "</nobr></p>";
}

if you wanna test to see if it fits just paste the code here 如果您想测试一下是否适合,只需在此处粘贴代码

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM