Implementing a list using display: inline-block without any specified order

Currently, I am immersed in a project that involves simulating an input using HTML and CSS. This input should be capable of executing a function like:

my_cool_function(param0, param1, param2, param3)
. To accomplish this, I have constructed an unordered list structure where the function itself is represented as a token, with each parameter also being treated as separate tokens. Here is the current HTML layout:

<ul class="list">
    <li class="token">
        <span>My_cool_Function</span>
        <ul class="tokenparams">
            <li class="token">
                <span>Param0</span>
            </li>
            <li class="token">
                <span>Param1</span></li>
            <li class="token">
                <span>Param2</span>
            </li>
            <li class="token">
                <span>Param3</span>
            </li>
        </ul>
    </li>
</ul>

When the width of the ul container is sufficient, everything displays properly. However, if the width is reduced, the layout breaks and I want it to wrap neatly. Below is the CSS code currently in use:

ul.list{
    height: auto;
    display: block;
    width: 600px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.428571429;
    color: #555;
    vertical-align: middle;
    background-color: #fff;
    border: 1px solid #ccc;
    cursor: text;
}
 
li.token{
    display: inline-block;
    white-space: nowrap;
    margin: 0 10px 0 0;
    padding: 0 1px 0 1px;
    border: 1px solid transparent;
    height: 18px;
    vertical-align: top;
    cursor: pointer;
}

li.token span {
    float:left;
}

li.active {
    border-color: #63B9FF;
}

ul.tokenparams {
    list-style-type: none;
    float: left;
    padding-left: 0;
}

ul.tokenparams::before {
    content: "(";
    float: left;
    margin-left: 2px;
}

ul.tokenparams::after {
    content: ")";
    margin-right: 2px;
}

ul.tokenparams .token:not(:last-child)::after{
    content: ",";
}

In the provided example, at 600px width it looks fine but at 355px width, issues arise:

I have included a fiddle demonstrating the problem: http://jsfiddle.net/jvxzLt2s/

My goal is to introduce a line break after param2 and param3, allowing for better readability.

Answer №1

This section will wrap each item within the ul.tokenparams li.tokens individually.

Visit this link to see the implementation

 
ul.list{
    height: auto;
    display: inline-block;
    width: auto;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.428571429;
    color: #555;
    vertical-align: middle;
    background-color: #fff;
    border: 1px solid #ccc;
    cursor: text;
}

input.input{
    border: 0;
    margin: 0;
    padding: 0;
    font-size: 12px;
    background-color: white;
    -webkit-appearance: caret;
}

li.token{
    display: inline-block;
    white-space: nowrap;
    margin: 0 10px 0 0;
    padding: 0 1px 0 1px;
    border: 1px solid transparent;
    height: 18px;
    vertical-align: top;
    cursor: pointer;
}
ul > li{float:left;}
li.token span {
    float:left;
}

li.active {
    border-color: #63B9FF;
}

ul.tokenparams {
    border: 1px solid transparent;
    display:inline;
    list-style-type: none;
    padding-left: 0;
    width:auto;

}

ul.tokenparams::before {
    content: "(";
    float: left;
    margin-left: 2px;
}

ul.tokenparams::after {
    content: ")";
    margin-right: 2px;
    float:left;
}

ul.tokenparams .token:not(:last-child)::after{
    content: ",";

}

Answer №2

Does this look like what you had in mind?

http://jsfiddle.net/jane_doe/bptwJYs8/5/

I have removed the height attributes from the CSS.

ul.list{
    /* Deleted 'height: auto;' from here */
    display: block;
    width: 350px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 1.428571429;
    color: #555;
    vertical-align: middle;
    background-color: #fff;
    border: 1px solid #ccc;
    cursor: text;
}

input.input{
    border: 0;
    margin: 0;
    padding: 0;
    font-size: 12px;
    background-color: white;
    -webkit-appearance: caret;
}

li.token{
    display: inline-block;
    white-space: nowrap;
    margin: 0 10px 0 0;
    padding: 0 1px 0 1px;
    border: 1px solid transparent;
    /* Deleted 'height: 18px;' from here */
    vertical-align: top;
    cursor: pointer;
}

li.token span {
    float:left;
}

li.active {
    border-color: #63B9FF;
}

ul.tokenparams {
    list-style-type: none;
    float: left;
    padding-left: 0;
}

ul.tokenparams::before {
    content: "(";
    float: left;
    margin-left: 2px;
}

ul.tokenparams::after {
    content: ")";
    margin-right: 2px;
}

ul.tokenparams .token:not(:last-child)::after{
    content: ",";
}

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

Why is it necessary to utilize absolute positioning in CSS?

Check out this link According to the link, an element with absolute positioning is placed in relation to its first parent element that has a position other than static. If no such element exists, then it refers to the containing block which is <html& ...

Searching for a substring within a larger string in JavaScript

I am trying to create a loop in JavaScript (Node.js) that checks if a string contains the "\n" character and then splits the string based on that character. <content>Hello </content><br /> <content>bob </content><br / ...

Retrieving selected item values in Angular 2 using ng2-completer

Recently, I decided to experiment with a new autocompleter tool that is unfamiliar to me: https://github.com/oferh/ng2-completer. I successfully imported it and it seems to be functioning properly. My current goal is to retrieve the values of the selecte ...

The measure of the leaflet map's vertical dimension in a Shiny module application

I'm facing an issue while trying to incorporate my small app as a module within my larger app. Everything seems to be working fine except for the height of the leaflet map. In the standalone app, I had: ui <- fluidPage( tags$style(type = "te ...

Avoid sudden page movements when validating user input

After successfully implementing the "Stars rating" feature from https://codepen.io/462960/pen/WZXEWd, I noticed that the page abruptly jumps up after each click. Determined to find a solution, I attempted the following: const labels = document.querySelect ...

CSS: Containers displayed side by side when screen width is above a certain threshold, otherwise stacked on top of each other

I am trying to make two containers responsive without using media queries or JavaScript. When the screen size is 500px or less, I want the containers to stack on top of each other and take up 100% of the screen width. But when the screen size exceeds 500 ...

Issue with displaying Bootstrap modal on top of another modal

Upon clicking the "Click me here" button, a modal pops up and displays a toast message expressing gratitude. The thank you modal should remain open on top of the save modal even after clicking save. However, upon saving, an error message appears: Cannot r ...

Creating a Rails application that dynamically fills a table with data from a

Encountering an issue with Ruby on Rails. I have a "Host Model" that contains a method which has a longer runtime. class Host < ActiveRecord::Base def take-a-while # implement logic here end Attempting to access a page where this method ru ...

File Upload yields a result of 'undefined'

Currently, I am utilizing Express File Upload. When attempting to send a post request to it, the error-handler returns an error indicating that no files were found. Upon logging console.log(req.files), it shows as undefined, causing the error to be sent ba ...

Are you able to develop a customized TestNG Listener to cater to your specific requirements?

I have developed a unique concept for a TestNG listener that meets my specific requirements. Essentially, I aim to design a custom listener that generates a report using a predefined HTML format. The crux of my idea revolves around declaring the listener ...

Incorporate a Background Image, which is linked to a website URL, by utilizing an external CSS file within

I am struggling to incorporate an external CSS file (specifically a background image from a URL) into my HTML document. I have successfully applied internal CSS, so the issue is not with the website link. Despite reviewing similar posts addressing comparab ...

The div is unable to display data retrieved from the php file using Ajax

This is the function utilizing ajax $(document).ready(function() { $('#submit').click(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: 'searchphp.php&apo ...

Version 5.0.4 of Mui, when used with makeStyles and withStyles, is experiencing issues with applying styles to Mui

I've been diving into a react project using Mui v5.0.4 and encountered an unexpected issue with my custom styles. Initially, everything was functioning smoothly, but suddenly the styles I had defined were no longer appearing as intended in components ...

Tips for accessing a unique window name in JavaScript

How can I make window.name persist between page refreshes? I need to use window.name to differentiate between multiple browser windows, allowing each one to display distinct data while sharing the same URL. However, my problem is that the value of window ...

Ways to access the req.user object within services

After implementing an authentication middleware in NestJs as shown below: @Injectable() export class AuthenticationMiddleware implements NestMiddleware { constructor() {} async use(req: any, res: any, next: () => void) { const a ...

Discovering the significance of a function's scope

I'm a bit confused about how the answer is coming out to be 15 in this scenario. I do understand that the function scope of doSomething involves calling doSomethingElse, but my calculation isn't leading me to the same result as 15. function doSo ...

There was a TypeError encountered while trying to read properties of undefined in Next.js version 13

I've encountered a problem in the title with my post API endpoint that I created in Next.js. The purpose of my endpoint is for form submission, where I gather inputs and send them to my email. Currently, my code successfully sends the email and I rec ...

Enhance Your File Uploads with Custom Images in Bootstrap

For the file upload buttons, I have used the given image by customizing the button look using Bootstrap 3. Here is an example of how I achieved this: <label class="btn btn-primary" for="my-file-selector"> <input id="my-file-selector" type="fi ...

PHP Database Query Automation

Looking to continuously query a database every .5 seconds in PHP to check for a specific field's status. Although I have achieved this functionality in Java, I am uncertain how to implement it in PHP due to the lack of threading support. While researc ...

Ways to expedite the process of retrieving data for a JavaScript array

Looking to acquire the creation date of 20000 files and save it in an array. The total time taken is 35 minutes, which seems quite lengthy. (Image Processing Time) Is there a method to generate the array with a quicker processing time? Are there any i ...