Ways to structure a div to resemble a table

I'm currently working on a form that has multiple input fields, and I'm looking to structure them in a specific way. The layout I want to achieve can be seen in this example:

https://jsfiddle.net/dmilos89/58ea82gj/2/

The example above utilizes a table structure, but I would like to achieve the same result using div elements. So far, this is what I have:

<div class="formItem">
    <div class="frRow">
        <div class="frCell">
            <span>Results</span>
        </div>
    </div>
    <div class="frRow">
        ...
    </div>
    <div class="frRow">
        ...
    </div>
    ...
</div>

Although I have made progress with my div structure, it's still not exactly what I'm aiming for. I've utilized CSS display properties to mimic the table structure. Here is the CSS I'm using:

div.frRow {
    margin: 5px;
    display: table;
}
div.frCell {
    display: table-cell;
    padding: 5px;
}
div.frCell span {
    font-weight: bold;
    margin-right: 5px;
}

I'm unsure if this is the most effective way to layout my form fields in this manner. I would appreciate any feedback on how I can achieve the desired layout or if there's a better approach to accomplish this. Thank you.

Answer №1

The structure of the table consists of table > row > cell as follows:

To achieve the table structure, you need to set the container formItem to display:table and the row frRow to display:table-row.

div.formItem {
  margin: 5px;
  display: table;
}

div.frRow {
  display: table-row;
}

div.frCell {
  display: table-cell;
  padding: 5px;
  border:1px solid #ccc;
}

div.frCell span {
  font-weight: bold;
  margin-right: 5px;
}
<div class="formItem">
  <div class="frRow">
    <div class="frCell">
      <span>Results</span>
    </div>
  </div>
  <div class="frRow">
    <div class="frCell">
      <span>Ear</span>
    </div>
    <div class="frCell" style="width:100px;min-width:100px;">
      <span>250</span>
    </div>
    <div class="frCell">
      <span>500</span>
    </div>
    <div class="frCell">
      <span>750</span>
    </div>
    <div class="frCell">
      <span>1000</span>
    </div>
    <div class="frCell">
      <span>1500</span>
    </div>
    <div class="frCell">
      <span>2000</span>
    </div>
    <div class="frCell">
      <span>3000</span>
    </div>
    <div class="frCell">
      <span>4000</span>
    </div>
    <div class="frCell">
      <span>6000</span>
    </div>
    <div class="frCell">
      <span>8000</span>
    </div>
  </div>
  <div class="frRow">
    <div class="formItem">
      <div class="frCell">
        <span>SRT<br>SAT</span>
      </div>
      <div class="frCell">
        <span>Recognition</span>
      </div>
    </div>
  </div>
</div>

Answer №2

insert this to your css style sheet

textfield{display:table;}
txtRow{display:table-row;}
txtCell{display:table-cell}

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

Differences in the way websites scroll on Chrome compared to Safari and Firefox

Currently, I am in the process of developing a rendering system for my application that extracts objects from a collection and processes them through JavaScript templates to generate additional children as the user scrolls through the page. The system is d ...

Greetings! I am interested in injecting HTML elements into a DOM using PHP and the jQuery Ajax method

After trying the following code snippet: $.ajax({ url: 'cod.php', type: 'POST', dataType: 'html', success: function(res){ $("#tests").html(res); } I implemented a foreach loop in my PHP s ...

Bootstrap is unable to function properly without jQuery, throwing an error message that states: "Bootstrap's JavaScript

Attempting to create a Bootstrap interface for a program. Added jQuery 1.11.0 to the <head> tag, however upon launching the web page in a browser, jQuery throws an error: Uncaught Error: Bootstrap's JavaScript requires jQuery Various attempts ...

Having trouble understanding why the other parts of my header are not displaying

<head> This special function runs when the webpage is loaded. <body onload="myOnload()"> A distinctive div at the top with a unique graphic <div id="header"> <img src="resumeheader.png" alt="Header" style="width:750px;h ...

How can I make sure that the combobox in my Ionic app is aligned with the text fields in a row?

From the image provided, it's evident that my HTML code looks like this: <ion-row> <ion-col> <ion-item> <searchable-ion-select isModal="true" name="country" valueField="code" [(ngModel)]="country" title="Country" ...

Ways to ensure "overflow: hidden" functions correctly across all web browsers

Issue: I am in the process of designing a webpage layout using divs and css instead of relying on an HTML table structure. It is essential for me to ensure that this design functions smoothly across all major browsers. The challenge I'm facing invol ...

checkbox toggling event triggering twice

I have been working on an application that allows users to register for university courses. They can select their registration type, course type, batch, and subjects. The subjects are displayed in a table based on the selected course type and batch. Users ...

Reveal and conceal information with a customized web address

I have a PHP and MySQL blog that I want to display in a div using show and hide JavaScript functions. Everything works fine with other divs, but the issue arises when clicking on a vanity URL causing my webpage to refresh every time it's clicked. The ...

Use jQuery to create a price filter that dynamically sets slide values based on the filter object

I'm currently utilizing the jQuery slide filter to sort products based on price. The filtering value is set within the script, but I am interested in dynamically setting it based on the highest/lowest number found on my page using a data attribute. D ...

Vue JS: Extracting both the unique ID and value from an array of input simultaneously

I am new to Vue and currently exploring its capabilities. I am experimenting with the Element UI for Vue's user interface. Specifically, I am working with the Input Number Component, to manage an array of data. Let's assume my data is structured ...

What is the reason for requiring a style to be set instead of using a class?

Trying to implement the footer staying at the bottom of my website like in this example. You can view my site here. The method is successful, however, I am required to apply the style style="min-height: 100vh;" directly to the body element inste ...

Range slider position not being updated after user interaction

I am working on a webpage with an embedded video and a range slider that serves as a progress bar. Using Javascript, I update the value of the range slider as the video plays, allowing users to navigate through the video content. However, I have encounter ...

Is there a way to access a comprehensive list of all the font names stored on my personal computer?

I'm currently working on a project that requires using local fonts only. Since I am using a Mac, I have located the fonts in /Library/Fonts. However, I have encountered an issue when trying to use a font named 华文黑体 directly in my CSS property: ...

What is causing the gradient to not fully extend across the entire element?

In my CSS, I have the following styling for a button: <a class="button"> <span>Y</span> </a> .button { -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-right-colors: none; ...

The webview is failing to display the dropdown menu

Everything seems to be working fine with the 3 dropdown menus on this website, as they appear on top of the images below them. However, when I convert the site into an Android app using Webview, the menus end up going under the images instead of on top. ...

Utilizing flexbox for dynamic width adjustment with flex-grow functionality

Currently, I am in the process of configuring a menu bar using this particular template I have been attempting to achieve this layout utilizing FlexBox, but it appears that there is an issue. Here is the HTML code: <nav> <ul> < ...

What could be causing the issue with my filter page not being able to retrieve any results from the

I am currently working on a filter page that is designed to display results in a table based on the selection made from a dropdown list. While I have written the necessary code and no errors are being detected, the results from the database are not showing ...

Adjust the width of a textarea dynamically as you type by detecting keyup events

Two text areas have the same text formatting. Their IDs are textareaA and textareaB. I've successfully added functionality to resize textareaA on keyup. How can I make textareaB resize its WIDTH while the user is typing in textareaA? Here's wha ...

Replace CSS property with a new CSS property

How can I remove a property from a class when using a library? For example, if the library has the following CSS: div { width: 100%; } And in your custom CSS file you want to remove the width property: div { width: none; //is this the correct w ...

How to customize the appearance of an HTML checkbox using custom images for a unique

Does anyone know how to change the default style for: <input type=checkbox...> I want it to use my own styled pictures instead of the default style. Can anyone help? Thank you! ...