css树列表更正

时间:2013-06-01 21:49:19

标签: css file list tree

我设法创建了目录的树列表并遇到了问题。

问题:

  1. 子文件夹与子文件不在同一列中。

  2. 子文件夹的行位于列的最后一个位置。

  3. preview

    如何解决?

    PHP:

      function ListFolder($path) {
            //using the opendir function
            $dir_handle = @opendir($path) or die("Unable to open $path");
    
            //Leave only the lastest folder name
            $dirname = end(explode("/", $path));
    
            echo '<ul>';
    
            //display the target folder.
            echo '<li><a href="'.$dirname.'" class="folder">'.$dirname.'</a>';
            echo '<ul>';
            while (false !== ($file = readdir($dir_handle))) {
                if ($file != "." && $file != "..") {
                    if (is_dir($path . "/" . $file)) {
                        //Display a list of sub folders.
                        ListFolder($path . "/" . $file);
                    } else {
                        //Display a list of files.
                        echo '<li><a href="'.$file.'">'.$file.'</a></li>';
                    }
                }
            }
            echo "</ul>";
            echo "</li>";
    
            echo "</ul>";
    
            //closing the directory
            closedir($dir_handle);
        }
    
        ListFolder("./files");
    

    这是行

    CSS:

    ul,
    ul ul {
        list-style:none;
        margin:0;
        padding:0;
    }
    
    ul ul {
        margin-left:10px;
        background:transparent url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAKAQMAAABPHKYJAAAAA1BMVEWIiIhYZW6zAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1ggGExMZBky19AAAAAtJREFUCNdjYMAEAAAUAAHlhrBKAAAAAElFTkSuQmCC') repeat-y 0 100%;
    }
    
    ul li {
        margin:0;
        padding:0 12px;
        font-size:14px;
        line-height:20px;
        color:#369;
        font-weight:bold;
    }
    
    ul ul li {
        background:transparent url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAUAQMAAACK1e4oAAAABlBMVEUAAwCIiIgd2JB2AAAAAXRSTlMAQObYZgAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YIBhQIJYVaFGwAAAARSURBVAjXY2hgQIf/GTDFGgDSkwqATqpCHAAAAABJRU5ErkJggg==') no-repeat 0 0;
    }
    
    ul ul li.last,
    ul ul li:last-child {
        background:white url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAUAQMAAACK1e4oAAAABlBMVEUAAwCIiIgd2JB2AAAAAXRSTlMAQObYZgAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YIBhQIIhs+gc8AAAAQSURBVAjXY2hgQIf/GbAAAKCTBYBUjWvCAAAAAElFTkSuQmCC') no-repeat 0 100%;
    background-position:left top;
    }
    

    HTML:

    <ul>
        <li><a href="test" class="folder">test</a>
            <ul>
                <li><a href="aaa.txt">aaa.txt</a></li>
                <li><a href="bbb.txt">bbb.txt</a></li>
                <ul>
                    <li><a href="subfolder" class="folder">subfolder</a>
                        <ul>
                            <li><a href="1.txt">1.txt</a></li>
                            <li><a href="2.txt">2.txt</a></li>
                        </ul>
                    </li>
                </ul>
                <li><a href="test.txt">test.txt</a></li>
            </ul>
        </li>
    </ul>
    

2 个答案:

答案 0 :(得分:1)

background-position:left top;添加到list.css文件的第29行。

Screenshot with CSS change

答案 1 :(得分:0)

一个标签在循环中,所以它自己重复。只需要使用一次。

php脚本的用法:

echo "<ul>";
ListFolder("files");
echo "</ul>";