K. Lykoudis K. Lykoudis - 5 months ago 9
HTML Question

Alter a table via css

im having this table from woocommerce products receipt print, and i have the following problem: Quantity column has a width: 15% value, but it looks like it takes 30% of the tables width and take alot of useful space.

does anyone have an idea why thats happening?

Also, how can i remove the 'price' column entirely via css without shrinking the table (keeping it 100% width)

There's my 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;
}
}


Thanks in advance for your time.

Answer

You can use :nth-child(). The CSS you need is:

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

Working Snippet

/*
 * 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 -->
  

Preview

enter image description here

Comments