Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I style a list of name-value pairs to appear like an HTML table?

Tags:

html

css

I have inherited a web forms report laid out using pure HTML and ASP.NET server controls, and a common layout pattern is a section laid out using a four column table, with first and third columns used for field labels, and the second and fourth columns for values.

As I've been tasked with 're-skinning' the report I thought I'd try and improve the semantics of the markup and remove all tables not used for actual tabular data. After some experiments with definition lists for name-value pairs, I settled instead on an ol/li combination, but I can't figure out how to get both text elements inside each li to occupy 50% of the width of the whole li element.

This is css for the list:

ol.name-value
{
    list-style: none;
    display: table;
}

ol.name-value li {
    display: table-row;
    border-bottom: 1px solid #E8E8E8;
}

This is the HTML:

<div class="span-12">
    <ol class="name-value" style="width: 100%;">
        <li>                    
            <label for="about">Client</label>
            <span id="about">Apartment Applied Visual Arts</span>
        </li>
        <li>
            <label for="about">Report Date</label>
            <span id="Span1">2011/08/08 16:50:10</span>
        </li>
        <li>
            <label for="about">Report No.</label>
            <span id="Span2">33251</span>
        </li>
    </ol>
</div>

And this is what I get as result. The Report Details section is a two-column table, where the Report Details is the above ordered list. I am trying to get the list

Illustration of styling that isn't working.

like image 759
ProfK Avatar asked Aug 08 '11 16:08

ProfK


People also ask

How do you style text in a table in HTML?

To style the text within a table, you use the same CSS properties that you would use in styling any text. The thing to remember is that, you need to know which HTML element to apply the style against. For example, to change the text color across the whole table, use the color property against the <table> tag.

What are name value pairs in HTML?

Name-value pairs are represented by a set of text strings in which name="value" are usually separated by commas, semicolons, space or newline character.

How do you add a style to HTML table Power automate?

Power Automate generates HTML code that can be easily modified or styled with help of CSS. Add a compose action as next step to Create HTML table action and enter below CSS to the compose action. Here is the formatted table and we can customize our html table / html code as per easy to complex requirements.


1 Answers

Try this:

ol.name-value {
    list-style: none;
    display: table;
}

ol.name-value li {
    display: table-row;
    border-bottom: 1px solid #E8E8E8;
}

ol.name-value li label {
    display: table-cell;
    width: 50%; 
}

ol.name-value li span {
    display: table-cell;
    width: 50%; 
}
like image 186
Rost Avatar answered Oct 24 '22 21:10

Rost