Как сделать так, чтобы два столбца в таблице имели одинаковую ширину? - PullRequest
0 голосов
/ 27 августа 2018

Я хотел сделать таблицу, аналогичную приведенной ниже: Screenshot of target table

Однако, как показано на скриншоте ниже, версия HTML вышла по-другому. Это довольно близко к тому, что я хочу сделать, но левая и правая ширина не равны, как я хочу. Вот скриншот: Screenshot of HTML table

Вот мой код:

# Empty CSS file for your own CSS

table {
    border-collapse: collapse;
    width: #D19F24;
    border: 1px solid #ddd;
}
td{
    text-align: center;
    font-weight: bold;
    border: 1px solid black;
}
tr{
  text-align: center;
  font-weight: bold;
}
.head{
  text-align: center;
}

.footer{
  text-align: left;
}
tr:nth-child(even){background-color:#D19F24;}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Table responsive</title>

    <meta name="description" content="made by Mitesh Chakma">
    <meta name="author" content="Mitesh Chakma">

    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

  </head>
  <body>

    <div style="overflow-x:auto;">
    <table>
      <tr>
        <td colspan="2"><a style="color:#D19F24;">Fabric Details</a></td>
      </tr>
      <tr>
        <td >Composition</td>
        <td>NA</td>
      </tr>
      <tr>
        <td>Colour <a style="color:#71B18F;">*</a></td>
        <td>NA</td>
      </tr>
      <tr>
        <td>Weight (g/m) <a style="color:#ff0000;">**</a></td>
        <td>NA</td>
      </tr>
      <tr>
        <td>Length (Meter)<a style="color: #ff0000;">***</a></td>
        <td>NA</td>
      </tr>
      <tr>
        <td>Width (cm)<a style="color:#ff0000;">****</a></td>
        <td>NA</td>
      </tr>
      <tr>
        <td>Name Edge</td>
        <td>NA</td>
      </tr>
      <tr>
        <td>Reference</td>
        <td>NA</td>
      </tr>
      <tr>
        <td>Additional Information</td>
        <td>NA</td>
      </tr>
        <td colspan="2">
          <p><a style="color:#ff0000;">*</a>Please be aware, the colour of the fabric on screen may differ from the actual fabric, depending on screen settings and other factors.</p>
          <p><a style="color:#71B18F;">*</a>Other colours may be available. Please check our other listings, visit our eBay shop/website or contact us</p>
          <p><a style="color:#ff0000;">**</a>The weight is always measured in grams per meter unless stated otherwise.</p>
          <p><a style="color:#ff0000;">***</a>The length stated in the Fabric Details is what you will receive when you purchase buy it now. More Lengths/custom lengths maybe available so get in touch with us</p>
          <p><a style="color:#ff0000;">****</a>The width is always in centimetres (CM) unless stated otherwise.</p>
      </td>
    </table>
  </div>

    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/scripts.js"></script>
  </body>
</html>

Я довольно новичок в этом и не могу понять, как добиться того, чего я хочу. Кроме того, если я хочу сделать эту таблицу отзывчивой, что я должен делать?

1 Ответ

0 голосов
/ 27 августа 2018

Вам следует установить width ваших td элементов на 50%, чтобы каждый из них занимал половину доступного пространства table (и, следовательно, имел одинаковую ширину). Кроме того, ваше table значение *1005* в настоящее время является цветом (#D19F24) - попробуйте установить его на 100%.

table {
  border-collapse: collapse;
  width: 100%;
  border: 1px solid #ddd;
}

td {
  text-align: center;
  width: 50%;
  font-weight: bold;
  border: 1px solid black;
}

tr {
  text-align: center;
  font-weight: bold;
}

.head {
  text-align: center;
}

.footer {
  text-align: left;
}

tr:nth-child(even) {
  background-color: #D19F24;
}
<div style="overflow-x:auto;">
  <table>
    <tr>
      <td colspan="2"><a style="color:#D19F24;">Fabric Details</a></td>
    </tr>
    <tr>
      <td>Composition</td>
      <td>NA</td>
    </tr>
    <tr>
      <td>Colour <a style="color:#71B18F;">*</a></td>
      <td>NA</td>
    </tr>
    <tr>
      <td>Weight (g/m) <a style="color:#ff0000;">**</a></td>
      <td>NA</td>
    </tr>
    <tr>
      <td>Length (Meter)<a style="color: #ff0000;">***</a></td>
      <td>NA</td>
    </tr>
    <tr>
      <td>Width (cm)<a style="color:#ff0000;">****</a></td>
      <td>NA</td>
    </tr>
    <tr>
      <td>Name Edge</td>
      <td>NA</td>
    </tr>
    <tr>
      <td>Reference</td>
      <td>NA</td>
    </tr>
    <tr>
      <td>Additional Information</td>
      <td>NA</td>
    </tr>
    <td colspan="2">
      <p><a style="color:#ff0000;">*</a>Please be aware, the colour of the fabric on screen may differ from the actual fabric, depending on screen settings and other factors.</p>
      <p><a style="color:#71B18F;">*</a>Other colours may be available. Please check our other listings, visit our eBay shop/website or contact us</p>
      <p><a style="color:#ff0000;">**</a>The weight is always measured in grams per meter unless stated otherwise.</p>
      <p><a style="color:#ff0000;">***</a>The length stated in the Fabric Details is what you will receive when you purchase buy it now. More Lengths/custom lengths maybe available so get in touch with us</p>
      <p><a style="color:#ff0000;">****</a>The width is always in centimetres (CM) unless stated otherwise.</p>
    </td>
  </table>
</div>

Что касается того, чтобы сделать его отзывчивым, это довольно широкий запрос, который открыт для интерпретации. Вы уже используете контейнер с overflow-x, установленным на auto, с относительными единицами измерения и включающим тег meta viewport, который помогает в отзывчивости.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...