none
Adding Left and Right Margin To Dynamically Generated Table Does not Work RRS feed

  • Question

  • I am using the below to generate an HTML table - the table is generated, however there is no padding added to the left or right margin.

    What would be the appropriate way to add in the padding to the margins of left and right?  (I want to add 1/2 inch)

    <table style='border:1px solid #666666; width:610px; margin-right:48px; margin-left:48px;'><colgroup>
    

    Monday, February 12, 2018 6:15 PM

Answers

  • Hello,

    Here is a thought, think beyond the standard margin settings along with knowing the container size e.g.

    <!DOCTYPE html>
    <html>
        <head>
            <style>
                .Container {
                    background-color: darksalmon;
                    width:700px;
                }
                table {
                    border-collapse: collapse;
                    width: 80%;
                    border: 1px solid #666666;
                    margin: 10px auto;
                }
    
                th, td {
                    border: 0 solid black;
                    width: 100px;
                    text-align: left;
                }
            </style>
        </head>
        <body>
            <div class="Container">
                <table>
                    <tr>
                        <td>Karen</td>
                        <td>Payne</td>
                    </tr>
                    <tr>
                        <td>Mary</td>
                        <td>Anderson</td>
                    </tr>
                </table>
            </div>
            
        </body>
    </html>
    
    So this structure may not work as is but perhaps give you ideas


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by IndigoMontoya Tuesday, February 13, 2018 2:22 PM
    Tuesday, February 13, 2018 2:35 AM
    Moderator

All replies

  • Hello,

    Here is a thought, think beyond the standard margin settings along with knowing the container size e.g.

    <!DOCTYPE html>
    <html>
        <head>
            <style>
                .Container {
                    background-color: darksalmon;
                    width:700px;
                }
                table {
                    border-collapse: collapse;
                    width: 80%;
                    border: 1px solid #666666;
                    margin: 10px auto;
                }
    
                th, td {
                    border: 0 solid black;
                    width: 100px;
                    text-align: left;
                }
            </style>
        </head>
        <body>
            <div class="Container">
                <table>
                    <tr>
                        <td>Karen</td>
                        <td>Payne</td>
                    </tr>
                    <tr>
                        <td>Mary</td>
                        <td>Anderson</td>
                    </tr>
                </table>
            </div>
            
        </body>
    </html>
    
    So this structure may not work as is but perhaps give you ideas


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by IndigoMontoya Tuesday, February 13, 2018 2:22 PM
    Tuesday, February 13, 2018 2:35 AM
    Moderator
  • The next sample file seems to work (in browsers and WebBroser control):

    <html>

    <body>

        <table style="border:1px solid #666666; width:610px; margin-right:0.5in; margin-left:0.5in;">

            <tr>

                <td>TEST</td>

                <td>TEST</td>

                <td>TEST</td>

            </tr>

            <tr>

                <td>TEST</td>

                <td>TEST</td>

                <td>TEST</td>

            </tr>

        </table>

    </body>

    </html>

     

    Perhaps you should give more details.


    • Edited by Viorel_MVP Tuesday, February 13, 2018 6:06 AM
    Tuesday, February 13, 2018 6:03 AM