html - 通过 css 修改表格

标签 html css

我有这张来自 woocommerce 产品收据打印的表格,我有以下问题:数量列的宽度:15% 值,但看起来它占用了表格宽度的 30% 并占用了大量有用空间。

有人知道为什么会这样吗?

此外,我如何通过 css 完全删除“价格”列而不缩小表格(保持 100% 宽度)

这是我的 fiddle :https://jsfiddle.net/ay7ys32L/2/

HTML:

    <div id="page">





                <article class="content">

                                       
                    <div class="company-info">
                        <h1 class="company-name">Flouskounis Food</h1>                      <div class="company-address"><p>2610 424342, Νοταρά 85</p>
</div>
                    </div>

                <div class="order-addresses">

                    <div class="billing-address">
                        <h3>Πελάτης:</h3>
                        <address>

                            customer name<br/>Κυρία<br/>address<br/>ισόγειο<br/>city<br/>Πελοπόννησος<br/>26225
                        </address>
                    </div>

                </div><!-- .order-addresses -->
                phone               
                <div class="order-items">
                    <table>
                        <thead>
                            <tr>
                                <th class="head-quantity"><span>quantity</span></th>
                                <th class="head-name"><span>item</span></th>
                                <th class="head-item-price"><span>price</span></th>
                                <th class="head-price"><span>total</span></th>
                            </tr>
                        </thead>

                        <tbody>


                                    <tr>
                                    <td class="product-quantity">
                                            <span>1</span>
                                        </td>
                                        <td class="product-name">

                                            <span class="name">Πίτα γύρος κοτόπουλο</span>

                                            <dl class="variation">
                        <dt class="variation-euro020">+:</dt>
                        <dd class="variation-euro020"><p>διπλό ζυμαράκι</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>Με υλικά της επιλογής σας</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>πατάτες</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>ντομάτα</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>τζατζίκι</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>μουστάρδα</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>σως μουστάδρας</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>μαγιονέζα</p>
</dd>

                        <dt class="variation-">+:</dt>
                        <dd class="variation-"><p>ροζ σως</p>
</dd>

                        <dt class="variation-euro020">+:</dt>
                        <dd class="variation-euro020"><p>μαρούλι</p>
</dd>

                        <dt class="variation-euro050">+:</dt>
                        <dd class="variation-euro050"><p>πιπεριά</p>
</dd>

                        <dt class="variation-euro050">+:</dt>
                        <dd class="variation-euro050"><p>καλαμπόκι</p>
</dd>

                        <dt class="variation-euro070">+:</dt>
                        <dd class="variation-euro070"><p>τυρί τριμμένο</p>
</dd>

                        <dt class="variation-euro070">+:</dt>
                        <dd class="variation-euro070"><p>σαγανάκι</p>
</dd>

                        <dt class="variation-euro070">+:</dt>
                        <dd class="variation-euro070"><p>φέτα</p>
</dd>
                    </dl>                                           
                                            <dl class="extras">

                                                                                            </dl>
                                        </td>
                                        <td class="product-item-price">
                                            <span><span class="amount">&euro;5.30</span></span>
                                        </td>

                                        <td class="product-price">
                                            <span><span class="amount">&euro;5.30</span></span>
                                        </td>
                                    </tr>


                                    <tr>
                                    <td class="product-quantity">
                                            <span>1</span>
                                        </td>
                                        <td class="product-name">

                                            <span class="name">Ντοματοσαλάτα</span>


                                            <dl class="extras">

                                                                                            </dl>
                                        </td>
                                        <td class="product-item-price">
                                            <span><span class="amount">&euro;5.20</span></span>
                                        </td>

                                        <td class="product-price">
                                            <span><span class="amount">&euro;5.20</span></span>
                                        </td>
                                    </tr>


                                    <tr>
                                    <td class="product-quantity">
                                            <span>1</span>
                                        </td>
                                        <td class="product-name">

                                            <span class="name">Χωριάτικη</span>


                                            <dl class="extras">

                                                                                            </dl>
                                        </td>
                                        <td class="product-item-price">
                                            <span><span class="amount">&euro;5.50</span></span>
                                        </td>

                                        <td class="product-price">
                                            <span><span class="amount">&euro;5.50</span></span>
                                        </td>
                                    </tr>
                                                                                    </tbody>

                        <tfoot>                         
                                                                                                <tr>
                                        <td class="total-name"><span>Subtotal</span></td>
                                        <td class="total-item-price"></td>
                                        <td class="total-quantity"></td>
                                        <td class="total-price"><span><span class="amount">&euro;16.00</span></span></td>
                                    </tr>
                                                                    <tr>
                                        <td class="total-name"><span>Shipping</span></td>
                                        <td class="total-item-price"></td>
                                        <td class="total-quantity"></td>
                                        <td class="total-price"><span>Delivery</span></td>
                                    </tr>
                                                                    <tr>
                                        <td class="total-name"><span>Total</span></td>
                                        <td class="total-item-price"></td>
                                        <td class="total-quantity"></td>
                                        <td class="total-price"><span><span class="amount">&euro;16.00</span></span></td>
                                    </tr>
                                                                                    </tfoot>
                    </table>

                                    </div><!-- .order-items -->


                <div class="order-notes">

                                    </div><!-- .order-notes -->




                <div class="order-colophon">
                    <div class="colophon-policies">
                                            </div>

                    <div class="colophon-imprint">
                                            </div>  

                                    </div><!-- .order-colophon -->

                </article><!-- .content -->






        </div><!-- #page -->

CSS:

    /*
 * Template: Default
 */

/* Simple CSS Reset and Print options
------------------------------------------*/


html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, table, ol, ul, dl, li, dt, dd {
    border: 0 none;
    font: inherit;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
}

body {
    line-height: 1;
}

ol,
ul {
    list-style: none;
}

table {
    border-collapse: collapse;
    border-spacing: 0;
}


/* Template Page Layout
------------------------------------------*/


/* Main Body */
body {
    background: #fff;
    color: #000;
    font-family: "HelveticaNeue", Helvetica, Arial, sans-serif;
    font-size: 100%;
    line-height: 1.25em;
}

h1,
h2,
h3,
h4 {
    font-weight: bold;
    margin-bottom: 1.2em;
}

ul {
    margin-bottom: 1.25em;
}

li,
dt,
dd  {
    padding: 0.375em 0;
}

dt {
    font-weight: bold;
}

p + p {
    margin-top: 1.25em;
}

address {
    font-style: normal;
}

/* Basic Table Styling */
table {
    page-break-inside: auto;
    width: 100%;
}

tr {
    page-break-inside: avoid;
    page-break-after: auto; 
    border-bottom: 0.12em solid #bbb;
}

td,
th {
    padding: 0.375em 0.75em 0.375em 0;
    vertical-align: top;
}

td img,
th img {
    vertical-align: top;
}

th {
    color: black;
    font-weight: bold;
    text-align: left;
    padding-bottom: 1.25em;
}

tfoot {
    display: table-row-group;
}

/* Page Margins & Basic Stylings */
#page {
    margin-left: 10px !important;
    margin-right: 10px;
    text-align: left;
    font-size: 16px;
}

.content {
    padding-left: 2%;
    padding-right: 2%;
    padding-top: 2%;
    padding-bottom: 2%;
}

.content + .content {
    page-break-before: always;
}

h1,
h2 {
    font-size: 1.572em;
}

.order-branding,
.order-addresses,
.order-info,
.order-items,
.order-notes,
.order-thanks,
.order-colophon {
    margin-bottom: 3em;
}

.order-items {
    page-break-before: auto;
    page-break-after: auto;
}

/* Order Branding */
.order-branding .company-logo {
    margin-bottom: 1em;
}

/* Order Addresses */
.order-addresses {
    margin-bottom: 10px;
}

.order-addresses:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}

.billing-address {
    width: 50%;
    float: left;
}

.shipping-address {
    width: 50%;
    float: left;
}

.order-addresses.no-shipping-address .shipping-address {
    display: none;
}

/*
.order-addresses.no-shipping-address .billing-address {
    margin-left: 50%;
}
*/

/* Switch the addresses for invoices */

/* Order Info */
.order-info ul {
    border-top: 0.24em solid black;
}

.order-info li {
    border-bottom: 0.12em solid #bbb;
}

.order-info li strong {
    min-width: 18%;
    font-weight: normal;
    display: inline-block;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    margin-bottom: 0;
    padding-right: 0.35em;
}

/* Order Items */
.order-items {
    margin-bottom: 0.5em;
}

.order-items .head-name,
.order-items .product-name,
.order-items .total-name {
    width: 50%;
}

.order-items .head-quantity,
.order-items .product-quantity,
.order-items .total-quantity,
.order-items .head-item-price,
.order-items .product-item-price,
.order-items .total-item-price {
    width: 15%;
}

.order-items .head-price,
.order-items .product-price,
.order-items .total-price {
    width: 20%;
}

.order-items p {
    display: inline;
}

.order-items small,
.order-items dt,
.order-items dd {
    font-size: 14px;
    font-weight: normal;
    line-height: 150%;
    padding: 0;
    margin: 0;
}

.order-items dt,
.order-items dd {
    display: block;
    float: left;
}

.order-items dt {
    clear: left;
    padding-right: 0.2em;
}

.order-items tfoot tr:first-child,
.order-items tfoot tr:last-child {
    font-weight: bold;
}

.order-items tfoot tr:last-child .total-price .amount:first-child {
    font-weight: bold;
}

.order-items tfoot tr:last-child {
    border-bottom: 0.24em solid black;
}

/* Order Notes */
.order-notes {
    margin-top: 3em;
    margin-bottom: 6em;
}

.order-notes h4 {
    margin-bottom: 0;
}

/* Order Thanks */
.order-thanks {
    margin-left: 50%;
}

/* Order Colophon */
.order-colophon {
    font-size: 0.785em;
    line-height: 150%;
    margin-bottom: 0;
}

.colophon-policies {
    margin-bottom: 1.25em;
}


/* CSS Media Queries for Print
------------------------------------------*/


@media print {
    body {
        font-size: 14px;
    }

    .content {
        /* Remove padding to not generate empty follow up pages */
        padding-bottom: 0;
    }
}

提前感谢您的宝贵时间。

最佳答案

您可以使用:nth-child()。您需要的 CSS 是:

.order-items table tr > *:nth-child(3) {
  display: none;
}

工作片段

/*
 * Template: Default
 */


/* Simple CSS Reset and Print options
------------------------------------------*/

html,
body,
div,
span,
h1,
h2,
h3,
h4,
h5,
h6,
p,
a,
table,
ol,
ul,
dl,
li,
dt,
dd {
  border: 0 none;
  font: inherit;
  margin: 0;
  padding: 0;
  vertical-align: baseline;
}

body {
  line-height: 1;
}

ol,
ul {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}


/* Template Page Layout
------------------------------------------*/


/* Main Body */

body {
  background: #fff;
  color: #000;
  font-family: "HelveticaNeue", Helvetica, Arial, sans-serif;
  font-size: 100%;
  line-height: 1.25em;
}

h1,
h2,
h3,
h4 {
  font-weight: bold;
  margin-bottom: 1.2em;
}

ul {
  margin-bottom: 1.25em;
}

li,
dt,
dd {
  padding: 0.375em 0;
}

dt {
  font-weight: bold;
}

p + p {
  margin-top: 1.25em;
}

address {
  font-style: normal;
}


/* Basic Table Styling */

table {
  page-break-inside: auto;
  width: 100%;
}

tr {
  page-break-inside: avoid;
  page-break-after: auto;
  border-bottom: 0.12em solid #bbb;
}

td,
th {
  padding: 0.375em 0.75em 0.375em 0;
  vertical-align: top;
}

td img,
th img {
  vertical-align: top;
}

th {
  color: black;
  font-weight: bold;
  text-align: left;
  padding-bottom: 1.25em;
}

tfoot {
  display: table-row-group;
}


/* Page Margins & Basic Stylings */

#page {
  margin-left: 10px !important;
  margin-right: 10px;
  text-align: left;
  font-size: 16px;
}

.content {
  padding-left: 2%;
  padding-right: 2%;
  padding-top: 2%;
  padding-bottom: 2%;
}

.content + .content {
  page-break-before: always;
}

h1,
h2 {
  font-size: 1.572em;
}

.order-branding,
.order-addresses,
.order-info,
.order-items,
.order-notes,
.order-thanks,
.order-colophon {
  margin-bottom: 3em;
}

.order-items {
  page-break-before: auto;
  page-break-after: auto;
}


/* Order Branding */

.order-branding .company-logo {
  margin-bottom: 1em;
}


/* Order Addresses */

.order-addresses {
  margin-bottom: 10px;
}

.order-addresses:after {
  content: ".";
  display: block;
  height: 0;
  clear: both;
  visibility: hidden;
}

.billing-address {
  width: 50%;
  float: left;
}

.shipping-address {
  width: 50%;
  float: left;
}

.order-addresses.no-shipping-address .shipping-address {
  display: none;
}


/*
.order-addresses.no-shipping-address .billing-address {
	margin-left: 50%;
}
*/


/* Switch the addresses for invoices */


/* Order Info */

.order-info ul {
  border-top: 0.24em solid black;
}

.order-info li {
  border-bottom: 0.12em solid #bbb;
}

.order-info li strong {
  min-width: 18%;
  font-weight: normal;
  display: inline-block;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  margin-bottom: 0;
  padding-right: 0.35em;
}


/* Order Items */

.order-items {
  margin-bottom: 0.5em;
}

.order-items .head-name,
.order-items .product-name,
.order-items .total-name {
  width: 50%;
}

.order-items .head-quantity,
.order-items .product-quantity,
.order-items .total-quantity,
.order-items .head-item-price,
.order-items .product-item-price,
.order-items .total-item-price {
  width: 15%;
}

.order-items .head-price,
.order-items .product-price,
.order-items .total-price {
  width: 20%;
}

.order-items p {
  display: inline;
}

.order-items small,
.order-items dt,
.order-items dd {
  font-size: 14px;
  font-weight: normal;
  line-height: 150%;
  padding: 0;
  margin: 0;
}

.order-items dt,
.order-items dd {
  display: block;
  float: left;
}

.order-items dt {
  clear: left;
  padding-right: 0.2em;
}

.order-items tfoot tr:first-child,
.order-items tfoot tr:last-child {
  font-weight: bold;
}

.order-items tfoot tr:last-child .total-price .amount:first-child {
  font-weight: bold;
}

.order-items tfoot tr:last-child {
  border-bottom: 0.24em solid black;
}


/* Order Notes */

.order-notes {
  margin-top: 3em;
  margin-bottom: 6em;
}

.order-notes h4 {
  margin-bottom: 0;
}


/* Order Thanks */

.order-thanks {
  margin-left: 50%;
}


/* Order Colophon */

.order-colophon {
  font-size: 0.785em;
  line-height: 150%;
  margin-bottom: 0;
}

.colophon-policies {
  margin-bottom: 1.25em;
}


/* CSS Media Queries for Print
------------------------------------------*/

@media print {
  body {
    font-size: 14px;
  }
  .content {
    /* Remove padding to not generate empty follow up pages */
    padding-bottom: 0;
  }
}

.order-items table tr > *:nth-child(3) {
  display: none;
}
<div id="page">
  <article class="content">

    <div class="company-info">
      <h1 class="company-name">Flouskounis Food</h1>
      <div class="company-address">
        <p>2610 424342, Νοταρά 85</p>
      </div>
    </div>

    <div class="order-addresses">

      <div class="billing-address">
        <h3>Πελάτης:</h3>
        <address>
          customer name<br/>Κυρία<br/>address<br/>ισόγειο<br/>city<br/>Πελοπόννησος<br/>26225
        </address>
      </div>

    </div>
    <!-- .order-addresses -->
    phone
    <div class="order-items">
      <table>
        <thead>
          <tr>
            <th class="head-quantity"><span>quantity</span></th>
            <th class="head-name"><span>item</span></th>
            <th class="head-item-price"><span>price</span></th>
            <th class="head-price"><span>total</span></th>
          </tr>
        </thead>

        <tbody>


          <tr>
            <td class="product-quantity">
              <span>1</span>
            </td>
            <td class="product-name">

              <span class="name">Πίτα γύρος κοτόπουλο</span>

              <dl class="variation">
                <dt class="variation-euro020">+:</dt>
                <dd class="variation-euro020">
                  <p>διπλό ζυμαράκι</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>Με υλικά της επιλογής σας</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>πατάτες</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>ντομάτα</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>τζατζίκι</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>μουστάρδα</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>σως μουστάδρας</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>μαγιονέζα</p>
                </dd>

                <dt class="variation-">+:</dt>
                <dd class="variation-">
                  <p>ροζ σως</p>
                </dd>

                <dt class="variation-euro020">+:</dt>
                <dd class="variation-euro020">
                  <p>μαρούλι</p>
                </dd>

                <dt class="variation-euro050">+:</dt>
                <dd class="variation-euro050">
                  <p>πιπεριά</p>
                </dd>

                <dt class="variation-euro050">+:</dt>
                <dd class="variation-euro050">
                  <p>καλαμπόκι</p>
                </dd>

                <dt class="variation-euro070">+:</dt>
                <dd class="variation-euro070">
                  <p>τυρί τριμμένο</p>
                </dd>

                <dt class="variation-euro070">+:</dt>
                <dd class="variation-euro070">
                  <p>σαγανάκι</p>
                </dd>

                <dt class="variation-euro070">+:</dt>
                <dd class="variation-euro070">
                  <p>φέτα</p>
                </dd>
              </dl>
              <dl class="extras">

              </dl>
            </td>
            <td class="product-item-price">
              <span><span class="amount">&euro;5.30</span></span>
            </td>

            <td class="product-price">
              <span><span class="amount">&euro;5.30</span></span>
            </td>
          </tr>


          <tr>
            <td class="product-quantity">
              <span>1</span>
            </td>
            <td class="product-name">

              <span class="name">Ντοματοσαλάτα</span>


              <dl class="extras">

              </dl>
            </td>
            <td class="product-item-price">
              <span><span class="amount">&euro;5.20</span></span>
            </td>

            <td class="product-price">
              <span><span class="amount">&euro;5.20</span></span>
            </td>
          </tr>


          <tr>
            <td class="product-quantity">
              <span>1</span>
            </td>
            <td class="product-name">

              <span class="name">Χωριάτικη</span>


              <dl class="extras">

              </dl>
            </td>
            <td class="product-item-price">
              <span><span class="amount">&euro;5.50</span></span>
            </td>

            <td class="product-price">
              <span><span class="amount">&euro;5.50</span></span>
            </td>
          </tr>
        </tbody>

        <tfoot>
          <tr>
            <td class="total-name"><span>Subtotal</span></td>
            <td class="total-item-price"></td>
            <td class="total-quantity"></td>
            <td class="total-price"><span><span class="amount">&euro;16.00</span></span>
            </td>
          </tr>
          <tr>
            <td class="total-name"><span>Shipping</span></td>
            <td class="total-item-price"></td>
            <td class="total-quantity"></td>
            <td class="total-price"><span>Delivery</span></td>
          </tr>
          <tr>
            <td class="total-name"><span>Total</span></td>
            <td class="total-item-price"></td>
            <td class="total-quantity"></td>
            <td class="total-price"><span><span class="amount">&euro;16.00</span></span>
            </td>
          </tr>
        </tfoot>
      </table>

    </div>
    <!-- .order-items -->

    <div class="order-notes">

    </div>
    <!-- .order-notes -->

    <div class="order-colophon">
      <div class="colophon-policies">
      </div>

      <div class="colophon-imprint">
      </div>

    </div>
    <!-- .order-colophon -->

  </article>
  <!-- .content -->

</div>
<!-- #page -->
  

预览

enter image description here

关于html - 通过 css 修改表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37625078/

相关文章:

javascript - 如何让 Canvas 在不剪切的情况下正确调整大小..特定脚本

html - 滚动体上具有 100% 高度行为的 div

css - block 元素,水平居中对齐和可能的最小宽度

jquery - 使用 jquery 管理 div 宽度是个好主意吗?

Python 正则表达式 : remove certain HTML tags and the contents in them

html - 我可以在 Bootstrap 3 中有部分重叠的列吗

html - Firefox 不支持 MP4?

Javascript 覆盖 CSS 样式不适用于关键帧动画

jquery - 使用 Powershell Where-Object 获取 src img

html - CSS : start scroll bar from specific div