3

我在显示以下代码时遇到了麻烦。我关心将 分为<div class="contectCode">两个<div class="left"><div class="right">。所以,switch的一些case应该显示在左边,一些显示在右边。

<?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;
}
4

2 回答 2

2

怎么样 :

.right
{
    float:left;
    text-align:right;
}
于 2013-02-12T00:46:18.560 回答
0

Ghadeer - 我可能在你的帖子中遗漏了一些东西,但我把你的 HTML 示例和 CSS 都拿走了,然后把它扔进了一个带有附加渲染的快速页面(在 Chrome v24 中,用颜色来显示布局)。在您的两个 HTML 示例中,右侧 div 中的文本与 div 的左侧对齐,因为text-align:left在您的内联样式中。

如果您想要右对齐的文本,请考虑text-align:right在您的.rightCSS 选择器中添加,并从<div class="right">...</div>元素中删除您的内联样式。

无论如何,这样维护起来要容易得多!

在旁注中,考虑到您正在逐字生成 HTML,为什么首先要有任何内联样式?看起来这些样式更适合放置在您的样式表中。

两个 HTML 示例的呈现

于 2013-02-12T04:35:36.213 回答