Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Center background image in table with CSS

<head>
    <style>
        table {
            background-image: url('./elements/pent.png');
            background-size: 100px, 100px;
            background-repeat: no-repeat;
            background-attachment: fixed;
            background-color: rgba(255, 255, 255, 0.7);
            background-blend-mode: overlay;
            background-position: center center;
            border: 1px solid #b3adad;
            border-collapse: collapse;
            padding: 5px;
        }
        table th {
            border: 1px solid #b3adad;
            padding: 5px;
            color: #313030;
        }
        table td {
            border: 1px solid #b3adad;
            text-align: center;
            padding: 5px;
            color: #313030;
        }
    </style>
</head>
<body>
    <table style="white-space:nowrap">
        <thead>
            <tr>
                <th><br></th>
                <th>Header1</th>
                <th>Header2</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Row<br></td>
                <td>1</td>
                <td>0.52</td>
            </tr>
            <tr>
                <td>Row</td>
                <td>1</td>
                <td>0.52</td>
            </tr>
            <tr>
                <td>Row</td>
                <td>1</td>
                <td>0.52</td>
            </tr>
            <tr>
                <td>Row</td>
                <td>1</td>
                <td>0.52</td>
            </tr>
            <tr>
                <td>Row</td>
                <td>1</td>
                <td>0.52</td>
            </tr>
            <tr>
                <td>Row</td>
                <td>1</td>
                <td>0.52</td>
            </tr>
            <tr>
                <td>Row</td>
                <td>150</td>
                <td></td>
            </tr>
        </tbody>
    </table>
</body>
</html>

This code centers the image in the middle of the window rather than the table itself. So, the position of the image in the background changes when I change the size of the window and is not always in the middle of the table.enter image description here

enter image description here

How can I make this be always centered in respect to the table and not the window?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Remove background-attachment: fixed;

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading