浮动到右侧的文本显示在左侧

3
我在下面的代码中遇到了一些问题。我想把<div class="contectCode">分割成两个部分<div class="left"><div class="right">。因此,有些情况应该在左侧显示,有些情况应该在右侧显示。
<?php

        $xml = simplexml_load_file("Profiles.xml");

        foreach($xml->children() as $Developer){ 
        echo '<div class="contectCode" style="height: 260px;">';

            echo '<div class="left" style="width:365px;">';
            echo '<b>' . $Developer['name'] . '</b>';
            echo '</div><br/>';

            echo '<div class="left"  style="width:365px; float:left; text-align:left;">';
            echo '<p><b><i>Communications with you</i></b></p>';
            echo '</div>';

            echo '<div class="right" style="width:365px; float:right; text-align:left;">';
            echo '<p><b><i>Communications with other developers </i></b></p>';
            echo '</div>';
            foreach($Developer->children() as $factor){

                switch ($factor->getName()){

                    case "trust":
                        echo '<div class="left" style="width:365px; float:left; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>You have selected (trusted) him to help you ' . $factor . ' times</p><br/>';
                        else
                            echo '<p>You have selected (trusted) her to help you ' . $factor . ' times</p><br/>';
                        echo '</div>';
                        break;
                    case "response":
                        echo '<div class="left" style="width:365px; float:left; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>He hes responded to your help request ' . $factor . ' times</p><br/>';
                        else
                            echo '<p>She has responded to your help request ' . $factor . ' times</p><br/>';
                        echo '</div>';
                        break;
                    case "indegreeOutdegree":
                        echo '<div class="left" style="width:365px; float:left; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>He has helped you to complete your code ' . $factor . ' times</p><br/>';
                        else
                            echo '<p>She has helped you to complete your code ' . $factor . ' times</p><br/>';
                        echo '</div>';
                        break;
                    case "recommended":
                        echo '<div class="left" style="width:365px; float:left; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>He has been recommended to you by others ' . $factor . ' times</p><br/>';
                        else
                            echo '<p>She has been recommended to you by others ' . $factor . ' times</p><br/>';
                        echo '</div>';
                        break;
                    case "trustG":
                        echo '<div class="right" style="width:365px; float:right; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>He has been selected (trusted) by others ' . $factor . ' times</p><br/>';
                        else 
                            echo '<p>She has been selected (trusted) by others ' . $factor . ' times</p><br/>';
                        echo '</div>';
                        break;
                    case "responseG":
                        echo '<div class="right" style="width:365px; float:right; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>He has responded to others requests ' . $factor . ' times</p><br/>';
                        else 
                            echo '<p>She has responded to others requests ' . $factor . ' times </p><br/>';
                        echo '</div>';
                        break;
                    case "indegreeOutdegreeG":
                        echo '<div class="right" style="width:365px; float:right; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>He has helped other developers ' . $factor . ' times</p><br/>';
                        else
                            echo '<p>She has helped other developers ' . $factor . ' times</p><br/>';
                        echo '</div>';
                        break;
                    case "recommendedG":
                        echo '<div class="right" style="width:365px; float:right; text-align:left;">';
                        if($Developer['gender'] == "Male")
                            echo '<p>He has been recommended to help by others ' . $factor . ' times</p><br/>';
                        else
                            echo '<p>She has been recommended to help by others ' . $factor . ' times</p><br/>';
                            echo '</div>';
                            break;
                }
            }

            echo '</div>';
        }



       ?>  

如果输出显示了左侧和右侧div中的情况,那么它就正常工作。但是,如果输出只显示了右侧div中的情况,它会将它们移到左侧。我想要在右侧而不是左侧显示它们。
那么,我应该怎么做呢?
CSS如下:
.contectCode
{
font-size:15px;
line-height:24px;
margin-left:13px;
margin-right:13px;
border-style:solid;
border-width:2px;
border-color:#000066;
padding:10px;
margin-top:5px;
margin-bottom:10px;
}

.left
{
float:left;
width:60%;
}

.right
{
float:left;
}

你能展示你的实际输出HTML吗? - Explosion Pills
2个回答

2
如何处理:
.right
{
    float:left;
    text-align:right;
}

0
Ghadeer - 我可能在你的帖子中漏掉了什么,但我将你的两个HTML示例和CSS放入了一个快速页面,并附上了呈现结果(在Chrome v24中,使用颜色显示布局)。 在你的两个HTML示例中,右侧div中的文本被对齐到div的左侧,因为你的内联样式中有text-align:left。
如果你想要右对齐的文本,请考虑在你的.right CSS选择器中添加text-align:right,并从
...
元素中删除你的内联样式。
这样做更容易维护!
另外,考虑到你正在逐字逐句地生成HTML,为什么要首先使用任何内联样式呢?看起来这些样式更适合放在你的样式表中。

Render of both HTML samples


不,我需要文本对齐方式为左对齐。我使用了float:right是因为我想让这个div在右侧,但是对齐仍然在左侧。 - Ghadeer Kintab

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接