3

次のコードの表示に問題があります。<div class="contectCode">を2<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;
}
4

2 に答える 2

2

どうですか:

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

Ghadeer - あなたの投稿には何かが欠けているかもしれませんが、あなたの HTML サンプルと CSS の両方を取得し、レンダリングを添付して簡単なページに放り込みました (Chrome v24 では、レイアウトを示す色を使用)。text-align:leftどちらの HTML サンプルでも、インライン スタイルのため、右側の div のテキストが div の左側に配置されています。

右揃えのテキストが必要な場合は、 CSS セレクターに追加text-align:rightし、要素からインライン スタイルを削除することを検討してください。.right<div class="right">...</div>

とにかく、そのように維持する方がはるかに簡単です!

余談ですが、HTML を逐語的に生成していることを考えると、そもそもインライン スタイルがあるのはなぜでしょうか。これらのスタイルは、スタイルシートにより適切に配置されるようです。

両方の HTML サンプルのレンダリング

于 2013-02-12T04:35:36.213 に答える