Attempting to use list elements in HTML to generate a table

I am having trouble creating a table that looks like this. I have never made a table like this before and would appreciate any guidance on how to achieve this style. Please help me out! All suggestions are welcome.

Below is the code snippet that I plan to use:

<html>
<body>
<style>
li{
border:1px solid black;
text-align:center;
}
</style>
   <ul style="list-style: none outside none;">
      <li style="float: left;display: block;width: 100px;height: 40px;">Field 1</li>
      <li style="float: left;display: block;width: 100px;height: 40px;">Field 2</li>
      <li style="float: left;display: block;width: 100px;height: 40px;">Field 3</li>
   </ul>
</body>
</html>

The image below will provide a visual of the desired output for better understanding.

Answer №1

One way to create a table layout from a list is by enclosing the list in a div and applying the following CSS:

<div class="table">
   <ul>
      <li>Field 1</li>
      <li>Field 2</li>
      <li>Field 3</li>
   </ul>
    <ul>
      <li>Field 1</li>
      <li>Field 2</li>
      <li>Field 3</li>
   </ul>
  </div>

CSS

.table {
  display:table;
  width:100%;
  border-top:1px solid #ddd;
  border-left:1px solid #ddd;
}
.table ul
{
  list-style:none;
  margin:0;
  padding:0;
  display:table-row;

}
.table ul li {
  display:table-cell;
  text-align:center;
   border-bottom:1px solid #ddd;
   border-right:1px solid #ddd;
  padding:2px 4px;
}

Check out the live demo here.

Answer №2

html

<body>
    <table border="1">
        <tr><th>row1</th><th>row2</th></tr>
        <tr><td>
           <ul>
              <li>Field 1</li>
              <li>Field 2</li>
              <li>Field 3</li>
           </ul></td>
            <td>X</td>
        </tr>
        <tr><td>
           <ul>
              <li>Field 1</li>
              <li>Field 2</li>
              <li>Field 3</li>
           </ul></td>
            <td>X</td>
        </tr>

</body>

css

li{
    display: block;
    float: left;
}

ul {
    list-style: none outside none;
}

EDIT: check out this link on jsfiddle

Answer №3

One way to organize your list items is by using nested ol and ul, as shown in the example below:

Example:

<ol class="table-list">
  <li>
    <ul class="table-list__inner">
      <li>Apples<span class="table-list__close">&times;</span></li>
      <li>Red<span class="table-list__close">&times;</span></li>
    </ul>
  </li>
  <li>
    <ul class="table-list__inner">
      <li>Bananas<span class="table-list__close">&times;</span></li>
      <li>Yellow<span class="table-list__close">&times;</span></li>
    </ul>
  </li>
</ol>

CSS Styling:

.table-list li {
  min-height: 70px;
  border: 1px solid gray;
  border-bottom-width: 0;
  position: relative;
}

.table-list li:last-child {
  border-bottom-width: 1px;
}

.table-list__inner {
  list-style: none;
  padding-left: 0;
}

.table-list__inner li {
  border-width: 0;
  border-bottom-width: 1px;
}

.table-list__inner li:last-child {
  border: 0;
}

.table-list__close {
  float: right;
  padding: 0.5em;
}

This structure can be effectively used with ngRepeat for AngularJS applications.

Answer №4

Check out this JSFIDDLE that is a bit complex but very close to what you need.

<div>
  <ul>
    <li class="fourth">x</li>
    <li class="third"><span class="icon">P</span> Text <span class="arrow">&#9660;</span></li>
    <li class="second">1</li>
    <li class="first">&middot;</li>

    <li class="fourth">x</li>
    <li class="third"><span class="icon">I</span> Text <span class="arrow">&#9660;</span></li>
    <li class="clear">&nbsp;</li>

    <li class="fourth">x</li>
    <li class="third small">Text <span class="arrow">&#9660;</span></li>
    <li class="clear">&nbsp;</li>

    <li class="fourth">x</li>
    <li class="third"><span class="icon">P</span> Text <span class="arrow">&#9660;</span></li>
    <li class="second">2</li>
    <li class="first">&middot;</li>

    <li class="fourth">x</li>
    <li class="third"><span class="icon">I</span> Text <span class="arrow">&#9660;</span></li>
    <li class="clear">&nbsp;</li>

    <li class="fourth">x</li>
    <li class="third"><span class="icon">I</span> Text <span class="arrow">&#9660;</span></li>
    <li class="clear">&nbsp;</li>

  </ul>

</div>


div {
  width: 470px;
  font-family: Verdana;
  font-size: 14px;
  letter-spacing: 1px;
  color: #222;
}
ul {
  float: left;
  list-style: none;
  margin: 0;
  padding: 0;
}
li {
  float: right;
  height: 35px;
  margin: -1px 0 0 -1px;
  padding-top: 15px;
  text-align: center;
  border: 1px solid #999;
}
.clear {
  width: 72px;
  border: none;
}
.first {
  width: 20px;
}
.second {
  width: 50px;
}
.third {
  width: 350px;
  padding-left: 10px;
  text-align: left;
}
.arrow {
  float: right;
  margin-right: 5px;
}
.icon {
  background: #333;
  display: inline-block;
  text-align: center;
  width: 20px;
  height: 18px;
  color: #fff;
}
.arrow:hover,
.fourth:hover {
  color: #555;
  cursor: pointer;
}
.fourth {
  width: 35px;
  clear: right;
}

Results:

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

The issue of overflow-y not functioning properly in conjunction with ng-repeat has been observed

As indicated in this resource, setting a fixed height for the div is suggested, but it seems like it's not working with the code provided below. <div style="margin-top:0.5vh;"> <div style="height:200px;border:1px solid red;overflow:au ...

Exploring the World of Html

I'm struggling with an HTML problem related to a web programming class I'm taking. The assignment involves creating a video game using HTML and JavaScript, where an image moves randomly on the screen and the player must click on it as many times ...

tips for adding text to an input field after it has been submitted

Is there a way to automatically add text to an input field after the user has entered their information? For example, if a user types "youtube.com" into a search bar, could the input then apply ""? ...

Can you provide me with instructions on how to create a toggle effect for a button using vanilla JavaScript?

Looking for guidance on creating a toggle effect with a button that switches between 2 images. I've managed to get it working with event listeners on btn2 and btn3, but can't seem to implement the 'toggle' effect on btn1. Any insights o ...

What is the best way to remove the background transparency of an image?

Images are being shown inside an HTML table using PHP code : This is the code for the table : for ($i = 0; $i < $data['list']['cnt']; $i++) { $tabRows[$i][1]['width'] = "45%"; $tabRows[$i][1][&apos ...

The size of jVectorMap is displayed too diminutive

Why isn't my jVectorMap adjusting to the new height I've specified for the containing div? It only displays at the default height of 54px. Within a document.ready function in my scripts.js file, I have the following code: $('#team-map-usa& ...

How can you horizontally align a collection of elements using CSS?

I'm struggling to align a paragraph element with a group of button elements using jQuery and CSS. This is my issue: My goal is to have all these elements on the same horizontal line at the top of the screen to make the most of the pixel real-estate. ...

What's the most effective method for implementing a stylesheet through Javascript in a style switcher?

I've been tackling the challenge of creating a style switcher for my website. Through utilizing .append() and if and else statements, I managed to make it work successfully. Take a look at the code below: HTML <select name="active_style" id="lol" ...

Is there a way to modify the way a screen-reading tool pronounces a specific word in a sentence without causing interruptions in the middle of the sentence?

Imagine I have the following sentence written in HTML: <p>Please input your licence number</p> An issue arises when a screen-reader pronounces the word 'licence' as "liss-ens" instead of "lice-ens." To resolve this, I aim to provide ...

"Vertical Line Encoding: A Strategy for Improved Data

Can someone help me with a coding issue I'm facing on my website? I am trying to create three vertical lines to separate images in columns, but every time I exit the editor and preview the site, the position of the lines changes. I'm new to HTML ...

Determining the number of columns and rows within an HTML table

Is there a way to determine the number of columns and rows in an HTML file? How can we accurately count the total number of td tags present within the HTML file? ...

Is it possible to animate CSS Grid components?

Is it possible to animate a re-ordered set of elements in an array that are arranged using a CSS Grid layout? Check out this quick boilerplate ...

Utilizing CSS classes to style custom day templates in ng-bootstraps datepicker

Currently, I am utilizing ng-bootstraps datepicker to showcase user data on a daily basis. I have implemented a custom day template to apply specific CSS classes. <ng-template #customDay let-date> <div class="custom-day" [ngCla ...

Tips for achieving a background animation similar to the one shown on this page

Check out this link: danielcoding.me/resume/#contact I am interested in this animation: screenshot I tried inspecting element on the page, but couldn't find any background images. How can I create this animation? Is it achieved through JavaScript or ...

Tips for defining types for specific CSS properties in TypeScript, such as variables

Perhaps there are already solutions out there, and I appreciate it if you can share a link to an existing thread. Nevertheless... In React, when I use the style prop, I receive good autocompletion and validation features like this example: https://i.sstat ...

Limit the radio button to being clickable

Ugh, I'm really struggling with this. I want to create a quiz where only the radio button is clickable, not the text itself. Can anyone help me figure out how to do this? I have two codes below that I don't quite understand. I'll include th ...

Utilizing identical CSS for both mobile and desktop interfaces, while customizing margins and paddings separately

I am facing a problem on my website where the padding and margins appear differently on different devices. I have compared screenshots of the site on an Android device and my desktop PC: Site displayed on mobile device: Desktop view: Below is the CSS co ...

Chat box custom scrollbar always positioned at the bottom

I have a personalized chat box where I included overflow-y for scrolling functionality. However, every time I input a message in the text box, it displays at the top of the scrollbar window. Is there a way to automatically show the most recent message I ...

Expanding the width of three floating divs in the center to match the width of the parent container div

In my design, I have a parent container with three inner divs that are floated. The left and right divs have fixed sizes, however, I need the center div to expand and fill the space available within the parent container. <div class="parent-container"&g ...

jQuery navigation is experiencing issues due to conflicting buttons

I am currently developing a web application that features two buttons in the header: Share and Options. When a button is clicked, its related content expands and collapses when clicked again. The issue arises when the user clicks on the share button and th ...