Align table with header

Asked

Viewed 180 times

2

How do I center the product table? A table has no Id or Class.

I wanted to take the table through javascript and modify its width to align with the header.

But it has id or class. I can only modify the header and footer of the page, so it has to be via javascript.

www.potinhodemel.com.br

  • You could create a minimum example that reproduces the problem, and post the code right here? You can [Edit] the question to include it. Thank you.

  • I wanted to take this element: <table border="0" cellpadding="0" cellspacing="0" width="100%"> , and change the width to align with the header.

1 answer

0


Basically is:

// CSS
h1{background:#FF0000}
table{background:#FFCC00}


// HTML
<h1>Heading</h1>

<table style="width:300px">
<tr><td>Teste</td></tr>
</table>


// JS
$( document ).ready(function(){
    $( 'table' ).width( $( 'h1' ).width() )
});

Demo running: jsfiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.