Ways to align a nested list vertically

There are two nested lists:

<ul>
    <li>First item
        <ul>
            <li> <a href="#">some item</a> 
            </li>
            <li> <a href="#">some item</a> 
            <</li>
            <li> <a href="#">some item</a> 
            </li>
        </ul>
    </li>
    <li>Second item
        <ul>
            <li> <a href="#">some item</a> 
            </li>
            <li> <a href="#">some item</a> 
            </li>
            <li> <a href="#">some item</a> 
            </li>
        </ul>
    </li>
</ul>

I want the first level of my list to be horizontally aligned, and the second level to be vertically aligned.

I have tried using the following CSS:

ul > li {
   display: inline-block;
}

However, this also applies to the second level (see fiddle). How can I achieve the desired effect?

Note: I also noticed that the bullet points disappear...

Answer №1

Give this a shot:

  ul > li > ul >li {
    visibility:hidden;
}

Answer №2

Greetings Fractaliste! Please take a look at the code below and let me know if you require any additional assistance.

<style type="text/css">
.navigation ul {
margin:0px;
padding:0px;
list-style: none;
}
.navigation li {
float: left;
height: 30px;
position: relative;
background-color: rgb(226, 226, 226);
padding-left: 15px;
padding-right: 15px;
padding-top: 8px;
}
.navigation li a {
text-decoration:none;
}
.navigation li a:hover {
text-decoration:underline;
}
.navigation li ul {
margin:0px;
padding:0px;
position: absolute;
left: -9999px;
height:30px;
}
.navigation li:hover ul
{
left: 0;
width:160px;
}
.navigation li:hover ul li
{
   background-color: rgb(226, 226, 226);
margin-bottom: 3px;
padding: 8px 10px 1px 10px;
}

</style>


<div class="navigation">
<ul>
<li><a href="index.html">menu1</a>
...
...
</div>

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

how to prevent autoscrolling in an angular application when overflow-x is set to

In my socket event, I am using $scope.items.unshift(item) to place the new item at the top of the list. The html code includes <ol ng-repeat="item in items"><li>{{item.name}}</li></ol> An issue arises when a new item is added whil ...

Methods for concealing the "image not found" icon in Internet Explorer and Chrome through CSS

I have images displayed on a webpage. Currently, when an image is not available, both Chrome and IE display a broken image indicator. I want to hide this indicator and only show the alternative text. Is there a CSS solution to achieve this? ...

Ensure that a div element expands to 100% of its parent's height when its child's height is less than 100%

I am struggling with a flex div that contains 2 elements. I want both elements to take up the full parent height while their content remains at auto height, but I keep getting the inner content height. Here is my code: <html lang="en"> <head&g ...

Users are reporting a problem with the PrimeNG confirmation dialog where it becomes unresponsive and locks up the screen

Previously functioning code seems to have been affected by an update to PrimeNG. The confirmation dialog that was once usable is now hidden behind a gray click-mask, rendering everything on the screen unclickable: The HTML structure for these two dialogs ...

You are only able to click the button once per day

I am working on a button that contains numeric values and updates a total number displayed on the page when clicked. I would like this button to only be clickable once per day, so that users cannot click it multiple times within a 24 hour period. Below i ...

Updating the .css file through the graphical user interface, within the managed bean

I have created a jsf page with colorpickers to allow an administrator to modify the main theme of the site, which consists of 4 colors. I have prefixed my main colors in the css file with numbers like this: .element{ background: /*1*/#333333; } When ...

The background color in CSS remains stagnant, refusing to change despite

Can someone help me figure out why the background color isn't changing in my simple code? I've double-checked that the external CSS is properly linked because the text color of h1 is changing. <!DOCTYPE html> <html> < ...

Can the Bootstrap grid be arranged vertically?

I'm finding it difficult to work on a project with Bootstrap's horizontal grid system. What I want to achieve is to have my page divided into 4 sections, with the left side blocks having equal height and the right side blocks having varying heigh ...

Discover the method for accessing a CSS Variable declared within the `:root` selector from within a nested React functional component

Motivation My main aim is to establish CSS as the primary source for color definitions. I am hesitant to duplicate these values into JavaScript variables as it would require updating code in two separate locations if any changes were made to a specific co ...

perfecting the styling of a tab management system

For reference, please check out the following link: http://jsfiddle.net/XEbKy/3/ In my design, I have organized two layers of tabs. The top layer consists of two tabs while the bottom layer has three tabs. My goal is to have all these tabs neatly enclosed ...

How to perfectly align a full-width div with a div of specific width

Consider this scenario: .d1 { width: 100px; float: left; } .d2 { width: auto; float: left; } <div class="d1">Fixed Content</div> <div class="d2">This content should expand to fill the rest of the page vertically.</div> This setu ...

Tips for defining CSS styles for the background color of <td> elements within a sitemap

I am facing a similar issue to the one discussed in this thread Possible to fill a table cell with a bg color?. The challenge I am encountering is related to applying CSS styles to the td tags within a sitemap structure. (Although it functions correctly ...

Webpack Encore: SCSS import order causing unexpected issues

When developing with Symfony + Webpack Encore, I aim to split styles into "layout" and "page-based" categories for convenience. However, despite this organization, I still prefer to compile all styles into a single CSS file. To achieve this, I structure my ...

Class name that changes the cursor to a pointer shape in CSS

My question is: Are there any CSS classes or attributes in Bootstrap 4 specifically designed for applying the pointer: cursor property to buttons or links? <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel= ...

Only one instance of a div with a table cell will function properly

I am facing an issue where I created a div with display:table-cell; and it appears as shown in the first picture, which is what I want. However, when I add another div, it changes to look like the second picture. All I want is for the text to be in the mid ...

What's the best way to make sure my table fits perfectly within its container's width?

I've encountered an issue with a table: If you want to see how the table was created, check it out on jsFiddle I attempted to modify the CSS like this : table{ width:100%; } td span { float:right; width:20%; text-align:center ...

The drop-down arrow in the <select> element seems determined to stay within the container

I am currently exploring alternative solutions (without the use of JavaScript) to address a Firefox bug that prevents styling the dropdown arrow in select elements. Some sources suggest placing the select element within a container and adjusting the contai ...

Can anyone provide a reference or resource that explains the best scenarios for utilizing display:block, display:inline, and display:inline-block, and the reasons behind their usage?

Can you recommend a quality article discussing the guidelines for using display:block, :inline, and :inline-block in CSS, along with explanations on when to utilize each one? Additionally, in what scenarios should we override the display property through ...

Reinitializing AngularJS form controls

Check out this codepen example: http://codepen.io/anon/pen/EjKqbW I'm trying to reset the form elements when the user clicks on "Reset". The div elements f1,f2,f3 should be hidden and the searchText box cleared. However, the reset button is not trig ...

Is it not possible to use a hyperlink and the general sibling combinator simultaneously?

Hi everyone, I'm completely new to CSS so please bear with me as I try to explain my issue. I'm attempting to create an image hyperlink using the .link class. I want the images for both .link and .picture to "change" when I hover over the hyperl ...