I can not align to the center or to the right the label th

-1

I'm aligning a list, I've managed to align the center with the <td> , but the <th> are rebellious, I leave my code:

<h1>Productos Disponibles</h1>
<table style="width:90%" border="1">

  <thead>
    <tr>
      <th>                <h4><%= "Nombre" %></h4></th>
      <th>                <h4><%= "Descripcion" %></h4></th>
      <th align="center" ><h4><%= "Existencia" %></h4></th>
      <th align="right" > <h4><%= "Precio" %></h4></th>
    </tr>
  </thead>

  <tbody>
    <% @productos.each do |producto| %>
      <tr>
          <td>                <h4><%= producto.nombre %></h4></td>
          <td>                <h4><%= producto.descripcion %></h4></td>
          <td align="center" ><h4><%= producto.cantidad_existencia %></h4></td>
          <td align="right" > <h4><%= producto.precio %></h4></td>

      </tr>
    <% end %>
  </tbody>
</table>

a sample of the output:

    
asked by rrg1459 01.07.2017 в 22:09
source

1 answer

1
  • the aling attribute is obsolete and is not being supported by html5, you should instead use CSS
  • The <th> default elements are in bold and centered
  • In any case to align a text you must use the CSS property

    text-align: center|right|left
    

    <h1>Productos Disponibles</h1>
    <table style="width:90%" border="1">
      <thead>
        <tr>
          <th>Nombre</th>
          <th>Descripcion</th>
          <th style="text-align: center">Existencia</th>
          <th>Precio</th>
        </tr>
      </thead>
    
      <tbody>    
          <tr>
              <td>nombre 1</td>
              <td>producto 1</td>
              <td style="text-align: center">10</td>
              <td style="text-align: right" >10.000</td>
          </tr>          
          <tr>
              <td>nombre 2</td>
              <td>producto 2</td>
              <td style="text-align: center">150</td>
              <td style="text-align: right" >36.500</td>
          </tr>  
      </tbody>
    </table>

    Only as a recommendation, make sure you have this label on the first line of your html output:

    <!doctype html>
    
      

    The Doctype or "Declaration of the document type" is an instruction   special that goes to the beginning of our HTML document and that allows the   browser understand what version of HTML we are using ... Read more

        
    answered by 01.07.2017 / 22:25
    source