CSS: improving the structure of lists

I successfully implemented a tree list of directory but I am encountering some issues.

Current Problems:

  1. Sub-folders are not in the same column as sub-files.

  2. Lines of sub-folders appear at the last spot of the column.

How can these issues be resolved?

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");

Highlighted lines:

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>

Answer №1

Ensure that you include the property background-position:left top; in line 29 of your stylesheet named list.css.

Answer №2

There was a loop that caused the tag to repeat itself unnecessarily. It only needed to be used once.

To utilize the PHP script:

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjusting the width of a kendo UI themed text field using CSS

Isn't it fascinating how you can adjust the width of a text box like this? @Html.TextBoxFor(m => m.LoginId, new { @class = "k-textbox", style="width:400px" }) However, I am seeking a more elegant solution. I attempted to implement this in a fres ...

Arrange the lines in a column with two on each side of the center column

Is there a way to align a column of divs like the image shown below, with two separate divs on either side of the main column? Here is what I currently have: <div id="waterfall"> <div class="fall" id="water1">Defaulter’s Initial Margin</ ...

Does the utilization of setTimeout(function, 100) have an impact on performance?

I have implemented a function that continuously checks if the URL contains any of the navigation hrefs every 100ms. If it finds a match, specific elements are assigned the class active. Here's the code snippet: var checkActive = function(){ ...

Is there a way to create an internal link to another HTML templating engine page within Express.js?

I am currently facing an issue with two Pug files, index.pug and search.pug, stored in a /views folder. In my index.pug file, I have the following line of code: a(href="/search.pug") Search In my JavaScript file, I have specified the view engine as P ...

I'm confused as to why the icon color isn't changing on the Blogger homepage for each individual user

I'm experimenting with changing the eye color based on visitor count. It works perfectly fine on static posts in my Blogger, but it fails to update the eye color properly on my homepage according to the set numeric values. Instead of displaying differ ...

Primeng Growl component in Angular doesn't wrap text to the next line

Currently, I am facing an issue in Angular/Javascript where the text in growl is not wrapping using primeng 4.0.1. The problem arises when inserting a long file path into the growl, causing it to overflow from a single line. I am looking for a solution tha ...

How can we incorporate an algorithmic solution into an Angular brand carousel?

I am seeking to create a brand slider in Angular without relying on any external libraries or packages. The functionality I desire is as follows: 1 2 3(active) 4 5 2 3 4(active) 5 6 3 4 5(active) 6 7 4 5 6(active) 7 (empty) 5 6 7(active) (empty) (empt ...

`Carousel nested within tabbed interface`

I am currently facing an issue with my website's tabs and carousels. I have 4 tabs, each containing a carousel, but only the carousel in the first tab seems to be working properly. When I activate the second tab, all the carousel divs collapse. For r ...

I am seeking assistance to utilize Flexbox to completely fill the height of my computer screen

Seeking assistance in utilizing Flexbox to occupy 100% of my computer screen's height, all while ensuring responsiveness: View of my current sign-in page on Chrome (Note the whitespace): https://i.sstatic.net/pJFOi.png Examining my existing fronten ...

Issue with Bootstrap 5: Mobile Menu Failure to Expand

I’ve been struggling with this issue for days now. I’ve searched everywhere for a solution, but to no avail. That’s why I’m turning to the experts here for help :-) The problem I’m facing is that my mobile menu won’t open. Nothing happens when ...

Is it possible to increase font sizes without changing the overall height of the text?

In my current project, I am experimenting with a CSS Grid layout featuring 2 rows and 1 column. Within this layout, I have placed a word that dominates the entire view-port by setting its font size to 23rem;. Inspired by this music album cover, I am attemp ...

What is the best way to convert a list of string values into integers to accurately represent specific data?

As a beginner in Python and coding, I carefully phrased my question. I have two sets of lists that are evenly populated – one representing family members and the other their ages. adams = ['ben', 'susan', 'billy'] adamsage = ...

Automatically add a class to the current list item in jQuery and remove the class from the

Here is my HTML code, where I am looking to dynamically swap the classes between two li elements every 2 seconds using jQuery. <li class=""> <a href="#"> <img src="client_logo01.png"> </a> </li> <li class= ...

It vanishes as soon as you move your cursor away during the animation

I created a button component with text animation, but I'm encountering an issue. When I hover over the button, the animation works smoothly. However, if I quickly move my cursor away or unhover in the middle of the animation, the text disappears unex ...

What is the best way to restrict user input to specific numbers only?

I have a text input field, how can I ensure that only numeric values from 1 to 31 are allowed? <input type="number" min="1" max="31"> ...

Is CSS Floating Causing Issues in Internet Explorer?

Encountering an issue with older versions of IE. I have three left-floated divs above three floated divs, each in separate wrappers. The lower divs are overlapping the upper ones specifically on older versions of IE; however, it works fine on Safari, mobil ...

Instructions for uploading multiple files to a website with Python and Selenium

Having trouble uploading multiple PGP files to a website using Python and Selenium. The script seems to only recognize the first file and not the rest. Any suggestions on how to fix this issue? I've checked my code, which includes the use of Selenium ...

Generate a CSV file from a MySQL database using PHP

<?php include("includes/config.php"); if ($_POST['frmCsv']) { $strSelect = performCsvSelection(); header( 'Content-Type: text/csv' ); header( 'Content-Disposition: attachment;filename=export.csv& ...

Restrict the width of an absolutely positioned element to the width of its

FIDDLE I have a situation where I need to position an element absolutely, like a drop-down menu. However, when the window is resized and becomes narrow, there is not enough space for it. My requirements are: - The right edge of the dropdown should not g ...

The function toggleClass() is malfunctioning

The .toggleClass() method seems to only be adding the "class" attribute to my selection, resulting in: <div id="toggle" class> ... rather than: <div id="toggle" class="on"> ... I've been trying to solve this issue for about 2 hours now ...