Table headers not aligning with table body












0














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>


enter image description here





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:



enter image description here










share|improve this question
























  • 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
















0














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>


enter image description here





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:



enter image description here










share|improve this question
























  • 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














0












0








0


1





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>


enter image description here





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:



enter image description here










share|improve this question















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>


enter image description here





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:



enter image description here







html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












3 Answers
3






active

oldest

votes


















0














Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.






share|improve this answer





























    0














    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.






    share|improve this answer





























      0














      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.






      share|improve this answer























        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
        });


        }
        });














        draft saved

        draft discarded


















        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









        0














        Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.






        share|improve this answer


























          0














          Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.






          share|improve this answer
























            0












            0








            0






            Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.






            share|improve this answer












            Surely it has to do with the align="left" that you have put on your col , remove it and it should be fine.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 28 '18 at 11:10









            Wembo MulumbaWembo Mulumba

            56136




            56136

























                0














                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.






                share|improve this answer


























                  0














                  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.






                  share|improve this answer
























                    0












                    0








                    0






                    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.






                    share|improve this answer












                    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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 28 '18 at 11:10









                    Guim GonzalezGuim Gonzalez

                    85112




                    85112























                        0














                        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.






                        share|improve this answer




























                          0














                          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.






                          share|improve this answer


























                            0












                            0








                            0






                            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.






                            share|improve this answer














                            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.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 29 '18 at 2:01

























                            answered Dec 29 '18 at 1:55









                            Mark D WolinskiMark D Wolinski

                            516




                            516






























                                draft saved

                                draft discarded




















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                Monofisismo

                                Angular Downloading a file using contenturl with Basic Authentication

                                Olmecas