Show a list in a row format within a positioned container

I've been experimenting with different methods to display a sub-list inline within an absolute container without any luck. I even tried using divs instead of the list, but that didn't work either. The only successful approach so far has been using tables, but I'm not too keen on that solution. Any suggestions?

ul.main > li {
display: inline-block;
position: relative;
background: red;
}

.sub{
position: absolute;
left: 0;
background: green;
}
ul..sub li {
display: inline-block;
}
<ul class="main">
  <li>
    1

    <ul class="sub">
      <li>1.1.</li>
      <li>1.1.</li>
      <li>1.1.</li>
    </ul>
  </li>
  <li>2</li>
</ul>

Answer №1

ul.main > li {
 display: inline-block;
 position: relative;
 background: red;
}

.sub{
 position: absolute;
 left: 0;
 background: green;
 white-space:nowrap;
 padding:0;
 list-style:none
}
ul.sub li {
 display:inline-block;
}
<ul class="main">
 <li>
   <span> 1</span>
     <ul class="sub">
       <li>1.1.</li>
       <li>1.1.</li>
       <li>1.1.</li>
    </ul>
 </li>
 <li>2</li>
</ul>

Answer №2

you’re getting close:

ul.main > li {
    float: left;
    //display: inline-block;
    position: relative;
    background: red;
}

ul.main > li > span{
    float:left;
    //display: inline-block;
}

.sub{
    background: green;
}
ul..sub li {
    display: inline-block;
}
<ul class="main">
  <li>
    <span>1</span>

    <span><ul class="sub">
      <li>1.1.</li>
      <li>1.1.</li>
      <li>1.1.</li>
    </ul></span>
  </li>
  <li>2</li>
</ul>

experiment with float:left or the display: inline-block technique

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

Start fresh with the count for every individual table

In my HTML document, I have multiple tables with columns that have classes "valuation" and "valuation_all". If one cell in the "valuation" column contains the text "FAIL", then the corresponding cell in the "valuation_all" column should display "FAIL"; oth ...

Tips for displaying a button when hovering over it on large screens and larger sizes

I am trying to achieve a specific behavior where the button with class .bookmark-btn is only visible on md size screens and smaller at all times. However, on lg size screens and bigger, it should only appear when hovered over. How can I accomplish this? Cu ...

SQL table not being updated by AJAX request data submission

I'm encountering an issue when trying to update a SQL table with form data sent via a JQuery AJAX POST. Even after using mysql_error(), no errors are being returned. As a troubleshooting step, I appended "-Test Test" to my textarea input. This addi ...

Styling X and Y axis font color in charts using JavaFX 2.x CSS

Is there a way to change the font color of both X and Y axes? In my search through the css reference for fonts, I only found properties like font-size, font-style, and font-weight. font-size, font-style and font-weight I attempted to use -fx-font-color ...

Small collapse Bootstrap navbar on col-sm width

I recently started experimenting with Bootstrap and implemented a collapsable navbar on my website. However, I noticed that on my Galaxy S6 phone, the navbar does not collapse into the button as expected when the screen size is reduced. Is there a way to ...

Implementing a Horizontal Navigation Menu for Categories in WordPress

Hello there, I am currently working on a WordPress website that has both parent categories and subcategories. My goal is to create a main horizontal menu with the parent category and have the subcategories appear as a submenu when hovering over the main c ...

Is there a way to access a private table in Google BigQuery using a Python script without needing an authorization token?

Is there a way to submit a query into Google's BigQuery and retrieve results from a python script without needing an authorization code for private tables? The python script is accessed through a user-friendly webpage, so manual authorization code han ...

Explore the data within a directory containing files and subfolders using javascript, HTML5, AngularJS, or jQuery

I'm looking to access and read files as well as subfolders within a folder that is selected using <input type="file"> I understand that I could potentially use <input type="file" multiple webkitdirectory />, but this solution is specific ...

Persistent footer overlaps lower body content

Issue with Sticky Footer in Safari I recently added a sticky footer to my website, but I'm facing problems with it covering the body content on Safari. It works fine on Chrome and Firefox after adding a bottom margin to the body to adjust for the hei ...

Instantly refreshing the display when a new item is inserted, removed, or modified in Angular

I am currently developing a task management application using Angular. While I have successfully implemented the functionality to add, delete, and edit tasks, the changes are not reflected in real-time on the web page. My goal is to enable users to see ne ...

An anomaly where a mysterious symbol appears in front of every dollar sign in an HTML document

I have a code written in AngularJS to display the amount in dollars. However, there is an unwanted " Â " character appearing before every " $ " character in the HTML. I am looking for a way to remove this character. Your help is greatly appreciated. Thank ...

An unexpected page transition occurs when attempting to delete a link

I've successfully created an HTML table that dynamically adds rows and provides an option to delete the current row. Each row represents data retrieved from MongoDB, and upon clicking the delete button, I aim to delete the corresponding item from the ...

Tips for properly applying the CSS display property to images

I have a piece of HTML code that includes an image of Rapunzel. The image has the style attribute set to display inline, but when I try to retrieve the display property using JavaScript, it always returns 'block' instead. I have tried using both ...

Tips for eliminating white spaces when text wraps onto a new line

Imagine having the following code snippet. Essentially, I have a layout that needs to display 'vs prev period' with a percentage in the same line. To achieve this, I utilized display: flex. The issue arises when we require the gap between the tw ...

Retrieve the order in which the class names are displayed within the user interface

In the following code snippet, each div element is assigned a common class name. <div id="category_9" class="list_item" data-item_ids="[38]"</div> <div id="category_2" class="list_item" data-ite ...

Using the Twit package on the client side: a step-by-step guide

I have been utilizing the Twit package for searching tweets. After executing the js file in the console, I am able to see the tweets but when trying to use them on my webpage, an error 'Uncaught ReferenceError: require is not defined' pops up. Th ...

I aim to adjust the width of a logo and ensure its size is fixed for optimal visibility

The selected logo needs to be more visible. I have attempted to use media queries to adjust its visibility, but I am having trouble with it. I want the logo to be able to stretch in width, but I am unsure how to achieve that. Currently, this is what I hav ...

Steps to create an iframe that opens in a new window

I'm facing an issue with the iframe sourced from flickr. My website includes an embedded flickr iframe to showcase a gallery without the hassle of creating a slider, resizing images, and extracting thumbnails. Given that this site belongs to a frien ...

What is the method to create an HTML div with a sloping edge?

my HTML & CSS code looks like this: https://i.sstatic.net/8vIaZ.jpg I would like it to look more like: https://i.sstatic.net/O9SA6.jpg Any tips on how I can achieve this?... ...

No matter what efforts I make, I can't seem to get .htaccess to work properly

Dealing with the .htacess file has always been a source of frustration for me. I am in need of some assistance. Here is my goal: I am currently using Ubuntu 14.04. I want to redirect my entire website (example.com) to a maintenance.html page. I also wan ...