The way in which LI elements are dynamically displayed

Check out this Fiddle!

I have a fiddle set up where li items are vertically aligned and floated to the right.

The issue I'm facing is with the order of the items - currently, they appear as test3, test2, and then test1. However, I want them to display in the order of test1, test2, and finally test3.

Any ideas on how I can fix this?

Just a note: The li items are dynamically pulled from a database.

HTML

<div id="wrapper">
    <ul>
        <li>test1</li>
        <li>test2</li>
        <li>test3</li>
    </ul>    
</div>    

CSS

#wrapper{
    width: 500px;
    height: 300px;
    background-color: yellow;
    display: table;
}

ul{
    display: table-cell;
    vertical-align: middle;
    text-align:right;
}

li{
    display: inline-block;
    text-align: center;
    padding: 30px;
    margin: 5px;
    background-color: red;
}

Answer №1

For optimal alignment of your list elements, it's best not to float them right. Instead, try aligning your <ul> text to the right. Since your list items are inline blocks, they will naturally follow this rule and line up from the right:

ul{
    display: table-cell;
    vertical-align: middle;
    text-align:right;
}

li{
    display: inline-block;
    text-align: center;
    padding: 30px;
    margin: 5px;
    background-color: red;
}

JSFiddle


Alternatively, you can print out the elements in reverse order:

<div id="wrapper">
    <ul>
        <li>test3</li>
        <li>test2</li>
        <li>test1</li>
    </ul>    
</div>   

JSFiddle

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

Tips for adjusting the color of a row when hovering

Can I modify the row color on hover in material-table using props? Similar to this example. Appreciate your help. ...

Variations in CSS Stylesheets for Various Parts of the Body

Currently, I am in the process of creating a single page website. One issue that I have encountered is needing a Bootstrap "modal" class popup to appear when a button is clicked. However, the template I am utilizing was designed using Bootstrap Version 1, ...

Display a <button> element as a text hyperlink within a paragraph, ensuring proper wrapping and flow

I want to incorporate a link-styled <button> within a block of text while ensuring that it flows smoothly with the surrounding content. Although styling the button is straightforward and setting display: inline allows it to blend into the text flow, ...

.scss compiling with errors

Recently, I embarked on a new Vue(3) project. Within this project, I have set up some basic styling in the App.scss file and created a HomeView.vue with a corresponding HomeView.scss file (located in the /src/views/Home directory). The styling from both fi ...

I would like to embed the HTML page within the specified div element

When attempting to load a HTML page inside the div, I encountered the following issue: <a href="#1" title="" class="base-banner" page="www.google.com for example"> <img src="images" alt=""></a> <div id="landingpage"> </div> ...

"Get rid of the arrow in Bootstrap's dropdown menu

I'm currently using a bootstrap template that features an accordion menu. However, I have come across a scenario on one section of the page where I do not require the items to expand and show additional text, therefore, I would like to remove the arro ...

Dealing with properties that are not found in Angular

Working on an existing code base, I am attempting to retrieve TextData from the mam-chart.model.ts file to populate a mat-form field in the design component. However, I am encountering an error that says "ERROR TypeError: Cannot read property 'text&ap ...

Transmit a parameter from a JavaScript code to a Python script

I am using a python script to execute queries in an Oracle Database by passing arguments. prov.py #!/usr/local/bin/python2.7 import sys import argparse import cx_Oracle import json import cgi import cgitb cgitb.enable() lst_proveedores=[{}] conn_str = & ...

How to create a responsive image that appears over a button when hovering in Bootstrap?

My goal is to display an image over a button when hovering. I've tried adding the .img-responsive class in Bootstrap while including the image in the HTML, but it's not working as expected with my current method of loading images. The buttons the ...

What is the best way to add a background image to a div without a fixed height in order for it to span the full width and

I am trying to incorporate a background image into a div element in such a way that it behaves like a background image in the body. I have looked at an example here: http://plnkr.co/edit/gFZZgPmSKMDu3gZEp1H0?p=preview where the width and height adjust ba ...

Choosing several buttons in typescript is a skill that every programmer must possess

I need help with selecting multiple buttons in TypeScript. The code I tried doesn't seem to be working, so how can I achieve this? var input = document.getElementById('input'); var result = document.getElementById('result'); v ...

Struggling to develop an age calculator tool that allows users to adjust the value using an up and down arrow function

https://i.sstatic.net/8Qjuf.png I'm currently working on a project that involves creating a tool to display a label with up and down arrows for adjusting the "Age" value. However, I've noticed that whenever I refresh the page, the functionality ...

What is the best method for transferring formatted text from the clipboard to an HTML textarea?

When you copy and paste from a web browser to a text processor, the HTML markup gets converted to rich text. The text processor then tries to convert this markup into its own format, proving that the Clipboard can hold markup. However, when you copy and p ...

Styling with CSS using only numerical values

My website features a section that states "Weekdays 10:00 ~ 18:00 /*linebreak/ Saturdays 10:00 ~ 13:30" I am looking to format only the numerical values in the font "Courier New," specifically the "10:00 ~ 18:00" and "10:00 ~ 13:30" sections. The remainin ...

Ensure that the table is padded while keeping the cells collapsed

I am currently working on creating a table with borders between each row. However, I am facing an issue where the row borders are touching the outer border of the table. Despite my efforts, I have been unable to find a solution to this problem. I feel like ...

A guide on extracting attribute values with special characters in HTML

I have a requirement where I need to extract an ID from a JSON response. This ID is in the format "TICKET NUMBER (TK)". In the HTML component, there is an attribute called CI which has the same value as the ID. However, when I try to access any attribute ...

Instructions on setting div opacity when Overflow is set to visibleExplanation on setting opacity for div with Overflow

In my HTML code, I have a div element and an image tag stacked one on top of the other. The div is smaller than the image. I have set the overflow property to visible for the div. My query is, when I add an image to the image tag, the content that overflow ...

Unable to display images in the ngImgCrop upload preview modal screen

Currently, I am utilizing ngImgCrop to enable an upload preview and square crop feature for profile pictures. Unfortunately, I am experiencing issues where neither the image preview nor the cropping functionality are being displayed. 'use strict ...

Is it ideal to have a single view for the entire Django website?

Imagine wanting to create a website using only one HTML template. One idea is to have a single view that handles all possible inputs and outcomes, such as when a new object is created by clicking a button and a form appears while the rest of the page remai ...

Which is better for cycling through a list of items: CSS or JavaScript?

Currently, I have a navigation bar set up as an unordered list (<ul>), but some list items are not visible. I want to implement functionality where clicking arrows will move the elements left or right by hiding or showing the leftmost or rightmost it ...