Table headers not aligning with table body
I'm trying to create headers for my table and the text isn't aligning with those entries in the bodies. Even when I do single characters. What seems to be the issue here? I've included the table code below and the image of how the table comes out.
<table style="width:100%">
<col align="left">
<col align="left">
<col align="left">
<col align="left">
<!-- HEADERS -->
<thead>
<tr>
<th scope="col">SYMBOL</th>
<th scope="col">PRICE</th>
<th scope="col">$ CHANGE</th>
<th scope="col">% CHANGE</th>
</tr>
</thead>
<tbody>
{% for item in view.display_stocks %}
<tr class="table table-striped">
<th scope ="row"><a href="search/stock_symbol={{ item.stock_symbol }}"><font color="#2C3E50">{{ item.stock_symbol }}</font></a></th>
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font><th>
<th><font color="red">{{ item.dollar_change }}</font><th>
<th><font color="red">{{ item.percent_change }}%</font><th>
{% else %}
<th><font color="green">${{ item.price }}</font><th>
<th><font color="green">+{{ item.dollar_change }}</font><th>
<th><font color="green">+{{ item.percent_change }}%</font><th>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
Edit: None of the answers seem to be fix the problem, but I just tried adding more columns in and there seems to be an extra two columns coming in the body from somewhere, here's a picture when I add two extra columns for the header:
html
add a comment |
I'm trying to create headers for my table and the text isn't aligning with those entries in the bodies. Even when I do single characters. What seems to be the issue here? I've included the table code below and the image of how the table comes out.
<table style="width:100%">
<col align="left">
<col align="left">
<col align="left">
<col align="left">
<!-- HEADERS -->
<thead>
<tr>
<th scope="col">SYMBOL</th>
<th scope="col">PRICE</th>
<th scope="col">$ CHANGE</th>
<th scope="col">% CHANGE</th>
</tr>
</thead>
<tbody>
{% for item in view.display_stocks %}
<tr class="table table-striped">
<th scope ="row"><a href="search/stock_symbol={{ item.stock_symbol }}"><font color="#2C3E50">{{ item.stock_symbol }}</font></a></th>
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font><th>
<th><font color="red">{{ item.dollar_change }}</font><th>
<th><font color="red">{{ item.percent_change }}%</font><th>
{% else %}
<th><font color="green">${{ item.price }}</font><th>
<th><font color="green">+{{ item.dollar_change }}</font><th>
<th><font color="green">+{{ item.percent_change }}%</font><th>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
Edit: None of the answers seem to be fix the problem, but I just tried adding more columns in and there seems to be an extra two columns coming in the body from somewhere, here's a picture when I add two extra columns for the header:
html
Maan, this code is very ancient even for table based layouts. Why do you use <th> in <tbody> section? Why <col align="left"> isn't closed anywhere? Make this code semantic for today's standards, column align shouldn't be a problem then.
– plvice
Dec 28 '18 at 11:09
"table table-striped" should be in the table itself not in each row assuming you're using Bootstrap?
– Nathan Champion
Dec 29 '18 at 2:00
add a comment |
I'm trying to create headers for my table and the text isn't aligning with those entries in the bodies. Even when I do single characters. What seems to be the issue here? I've included the table code below and the image of how the table comes out.
<table style="width:100%">
<col align="left">
<col align="left">
<col align="left">
<col align="left">
<!-- HEADERS -->
<thead>
<tr>
<th scope="col">SYMBOL</th>
<th scope="col">PRICE</th>
<th scope="col">$ CHANGE</th>
<th scope="col">% CHANGE</th>
</tr>
</thead>
<tbody>
{% for item in view.display_stocks %}
<tr class="table table-striped">
<th scope ="row"><a href="search/stock_symbol={{ item.stock_symbol }}"><font color="#2C3E50">{{ item.stock_symbol }}</font></a></th>
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font><th>
<th><font color="red">{{ item.dollar_change }}</font><th>
<th><font color="red">{{ item.percent_change }}%</font><th>
{% else %}
<th><font color="green">${{ item.price }}</font><th>
<th><font color="green">+{{ item.dollar_change }}</font><th>
<th><font color="green">+{{ item.percent_change }}%</font><th>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
Edit: None of the answers seem to be fix the problem, but I just tried adding more columns in and there seems to be an extra two columns coming in the body from somewhere, here's a picture when I add two extra columns for the header:
html
I'm trying to create headers for my table and the text isn't aligning with those entries in the bodies. Even when I do single characters. What seems to be the issue here? I've included the table code below and the image of how the table comes out.
<table style="width:100%">
<col align="left">
<col align="left">
<col align="left">
<col align="left">
<!-- HEADERS -->
<thead>
<tr>
<th scope="col">SYMBOL</th>
<th scope="col">PRICE</th>
<th scope="col">$ CHANGE</th>
<th scope="col">% CHANGE</th>
</tr>
</thead>
<tbody>
{% for item in view.display_stocks %}
<tr class="table table-striped">
<th scope ="row"><a href="search/stock_symbol={{ item.stock_symbol }}"><font color="#2C3E50">{{ item.stock_symbol }}</font></a></th>
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font><th>
<th><font color="red">{{ item.dollar_change }}</font><th>
<th><font color="red">{{ item.percent_change }}%</font><th>
{% else %}
<th><font color="green">${{ item.price }}</font><th>
<th><font color="green">+{{ item.dollar_change }}</font><th>
<th><font color="green">+{{ item.percent_change }}%</font><th>
{% endif %}
</tr>
{% endfor %}
</tbody>
</table>
Edit: None of the answers seem to be fix the problem, but I just tried adding more columns in and there seems to be an extra two columns coming in the body from somewhere, here's a picture when I add two extra columns for the header:
html
html
edited Dec 28 '18 at 20:14
Buk Lao
asked Dec 28 '18 at 11:04
Buk LaoBuk Lao
11215
11215
Maan, this code is very ancient even for table based layouts. Why do you use <th> in <tbody> section? Why <col align="left"> isn't closed anywhere? Make this code semantic for today's standards, column align shouldn't be a problem then.
– plvice
Dec 28 '18 at 11:09
"table table-striped" should be in the table itself not in each row assuming you're using Bootstrap?
– Nathan Champion
Dec 29 '18 at 2:00
add a comment |
Maan, this code is very ancient even for table based layouts. Why do you use <th> in <tbody> section? Why <col align="left"> isn't closed anywhere? Make this code semantic for today's standards, column align shouldn't be a problem then.
– plvice
Dec 28 '18 at 11:09
"table table-striped" should be in the table itself not in each row assuming you're using Bootstrap?
– Nathan Champion
Dec 29 '18 at 2:00
Maan, this code is very ancient even for table based layouts. Why do you use <th> in <tbody> section? Why <col align="left"> isn't closed anywhere? Make this code semantic for today's standards, column align shouldn't be a problem then.
– plvice
Dec 28 '18 at 11:09
Maan, this code is very ancient even for table based layouts. Why do you use <th> in <tbody> section? Why <col align="left"> isn't closed anywhere? Make this code semantic for today's standards, column align shouldn't be a problem then.
– plvice
Dec 28 '18 at 11:09
"table table-striped" should be in the table itself not in each row assuming you're using Bootstrap?
– Nathan Champion
Dec 29 '18 at 2:00
"table table-striped" should be in the table itself not in each row assuming you're using Bootstrap?
– Nathan Champion
Dec 29 '18 at 2:00
add a comment |
3 Answers
3
active
oldest
votes
Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.
add a comment |
You should use <td>
instead of <th>
inside the table body. Also, you have these classes in the body <tr class="table table-striped">
that you don't in the head.
add a comment |
Well, you should probably close your th’s in your body correctly and that would probably fix the issue:
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font></th>
<th><font color="red">{{ item.dollar_change }}</font></th>
<th><font color="red">{{ item.percent_change }}%</font></th>
{% else %}
<th><font color="green">${{ item.price }}</font></th>
<th><font color="green">+{{ item.dollar_change }}</font></th>
<th><font color="green">+{{ item.percent_change }}%</font></th>
{% endif %}
The body code you have will automatically close the th and then create a second one, which is why your columns are getting off set.
That being said, I agree with other commenters that generally speaking, you should use td instead of th for body cells and use CSS to style the content as you would like it.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957505%2ftable-headers-not-aligning-with-table-body%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.
add a comment |
Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.
add a comment |
Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.
Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.
answered Dec 28 '18 at 11:10
Wembo MulumbaWembo Mulumba
56136
56136
add a comment |
add a comment |
You should use <td>
instead of <th>
inside the table body. Also, you have these classes in the body <tr class="table table-striped">
that you don't in the head.
add a comment |
You should use <td>
instead of <th>
inside the table body. Also, you have these classes in the body <tr class="table table-striped">
that you don't in the head.
add a comment |
You should use <td>
instead of <th>
inside the table body. Also, you have these classes in the body <tr class="table table-striped">
that you don't in the head.
You should use <td>
instead of <th>
inside the table body. Also, you have these classes in the body <tr class="table table-striped">
that you don't in the head.
answered Dec 28 '18 at 11:10
Guim GonzalezGuim Gonzalez
85112
85112
add a comment |
add a comment |
Well, you should probably close your th’s in your body correctly and that would probably fix the issue:
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font></th>
<th><font color="red">{{ item.dollar_change }}</font></th>
<th><font color="red">{{ item.percent_change }}%</font></th>
{% else %}
<th><font color="green">${{ item.price }}</font></th>
<th><font color="green">+{{ item.dollar_change }}</font></th>
<th><font color="green">+{{ item.percent_change }}%</font></th>
{% endif %}
The body code you have will automatically close the th and then create a second one, which is why your columns are getting off set.
That being said, I agree with other commenters that generally speaking, you should use td instead of th for body cells and use CSS to style the content as you would like it.
add a comment |
Well, you should probably close your th’s in your body correctly and that would probably fix the issue:
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font></th>
<th><font color="red">{{ item.dollar_change }}</font></th>
<th><font color="red">{{ item.percent_change }}%</font></th>
{% else %}
<th><font color="green">${{ item.price }}</font></th>
<th><font color="green">+{{ item.dollar_change }}</font></th>
<th><font color="green">+{{ item.percent_change }}%</font></th>
{% endif %}
The body code you have will automatically close the th and then create a second one, which is why your columns are getting off set.
That being said, I agree with other commenters that generally speaking, you should use td instead of th for body cells and use CSS to style the content as you would like it.
add a comment |
Well, you should probably close your th’s in your body correctly and that would probably fix the issue:
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font></th>
<th><font color="red">{{ item.dollar_change }}</font></th>
<th><font color="red">{{ item.percent_change }}%</font></th>
{% else %}
<th><font color="green">${{ item.price }}</font></th>
<th><font color="green">+{{ item.dollar_change }}</font></th>
<th><font color="green">+{{ item.percent_change }}%</font></th>
{% endif %}
The body code you have will automatically close the th and then create a second one, which is why your columns are getting off set.
That being said, I agree with other commenters that generally speaking, you should use td instead of th for body cells and use CSS to style the content as you would like it.
Well, you should probably close your th’s in your body correctly and that would probably fix the issue:
{% if item.percent_change < 0 %}
<th><font color="red">${{ item.price }}</font></th>
<th><font color="red">{{ item.dollar_change }}</font></th>
<th><font color="red">{{ item.percent_change }}%</font></th>
{% else %}
<th><font color="green">${{ item.price }}</font></th>
<th><font color="green">+{{ item.dollar_change }}</font></th>
<th><font color="green">+{{ item.percent_change }}%</font></th>
{% endif %}
The body code you have will automatically close the th and then create a second one, which is why your columns are getting off set.
That being said, I agree with other commenters that generally speaking, you should use td instead of th for body cells and use CSS to style the content as you would like it.
edited Dec 29 '18 at 2:01
answered Dec 29 '18 at 1:55
Mark D WolinskiMark D Wolinski
516
516
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53957505%2ftable-headers-not-aligning-with-table-body%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maan, this code is very ancient even for table based layouts. Why do you use <th> in <tbody> section? Why <col align="left"> isn't closed anywhere? Make this code semantic for today's standards, column align shouldn't be a problem then.
– plvice
Dec 28 '18 at 11:09
"table table-striped" should be in the table itself not in each row assuming you're using Bootstrap?
– Nathan Champion
Dec 29 '18 at 2:00