Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
98 views
in Technique[技术] by (71.8m points)

node.js - HTML table not showing correctly

this might look like the most dumb question of all time, but after passing a JSON object to EJS , my table is not dividing the information in cells and rows, but just showing them in one row with comasenter image description here

this is my code

app.get("/", function (req, res) {
  const data = require("./data.json");
  var recetas = data;
  res.render("pages/index", {
    recetas: recetas,
  });
});
<head>
    <%- include('../partials/head'); %>
  </head>
  <body class="container">
   
    <header><%- include('../partials/header'); %></header>

    <main>
      <div class="jumbotron">
      
        <h2>Receta</h2>

        <ul>
          <% recetas.forEach(function(receta) { %>
          <li>
            <h1><strong>Nombre</strong></h1>
            <p><%= receta.nombre %></p>
            <h2><strong>Categoria</strong></h2>
            <p><%= receta.categoria %></p>
            <h2><strong>Chef</strong></h2>
            <p><%= receta.chef %></p>
    
            <table style="width:100% ; border:1px solid black ; border-collapse: collapse;padding: 15px" >
              <tbody>
                <tr>
                
                </tr>
                    <tbody>
                        <tr style="height: 18px ; border: 1px solid black;
                        border-collapse: collapse;padding: 15px">
                          <td style="width: 50%; height: 18px; text-align: justify ; border: 1px solid black;
                          border-collapse: collapse;padding: 15px">
                            <strong>Ingrediente</strong>&nbsp;
                          </td>
                          <td style="width: 50%; height: 18px; text-align: justify">
                            <strong>Cantidad</strong>
                          </td>
    
                        <tr style="height: 18px ; border: 1px solid black;
                        border-collapse: collapse;padding: 15px">
                          <td style="width: 50%; height: 18px; text-align: justify ; border: 1px solid black;
                          border-collapse: collapse;padding: 15px">        <%= receta.ingredientes.nombre %>
                          </td>
                          
                          <td style="width: 50%; height: 18px; text-align: justify ; border: 1px solid black;
                          border-collapse: collapse;padding: 15px">        <p><%= receta.ingredientes.cantidad %></p>
                          </td>
                        </tr>
                    </tr>
    
                      </tbody>
                    </table>
    
                
           
     
          </li>
        
          <h2><strong>Preparacion</strong></h2>
          <textarea id="w3review" name="w3review" rows="4" cols="50">
            <%= receta.preparacion %></textarea>
            <% }); %>
        </ul>
      </div>
    </main>

    <footer><%- include('../partials/footer'); %></footer>
  </body>
</html>

that is all of my code and I have no idea how to solve this, im kinda new to web programming so, please help me with this

thanks a lot

question from:https://stackoverflow.com/questions/65920406/html-table-not-showing-correctly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your html table is not valid at all, you can find lesson here https://www.dummies.com/programming/how-to-create-an-html-table/

Your table must include 1 <tbody> you have two, with one not closed :

<table>
    <tbody>
      <tr>
      </tr>
      <tbody>
        ...
      </tbody>
</table>

You're including <tr> inside <tr> witch is wrong

<tr>
     <td>
         ...
     </td>
     <tr>
        ...
     </tr>
    </tr>

You must have something like this, your <table> must include only one <tbody> in which you can include <tr> in which you can include <td>

table, th, td {
  border: 1px solid black;
}
<table>
  <tbody>
    <tr>
      <td>col1 row 1</td>
      <td>col2 row 1</td>
    </tr>
  <tr>
    <td>col1 row 2</td>
    <td>col2 row 2</td>
  </tr>
  <tr>
     <td colspan="2">col 1</td>
  </tr>
  </tbody>
</table>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...