Move image from table cell to top left of browser window using only css

I am doing cosmetic changes on the website, but I can only change the CSS, not the aspx. I want to move the image that is inside a cell into a table set on the page by about 100 / 100px to 0 / 0px.

The tag has a unique id which I can get, but the table id is not unique and setting the background image to the table from css affects other parts of the site. I also tried to set a background image on the body, however this page is a set of frames where each frame links to the same stylesheet. As a result, I get a background image in every frame.

A very simplified version of the html is this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>move image</title>
        <style type="text/css">
            #imgLogo {/*how can I move this to 0,0?*/}
        </style>
    </head>
    <body>
        <table style="margin-left:100px; margin-top:100px;">
            <tr>
                <td>
                    <img id="imgLogo" src="http://www.google.com/intl/en_ALL/images/logo.gif" alt="google" />
                </td>
            </tr>
        </table>
    </body>
</html>

      

EDIT

Thanks to everyone who said to use absolute position. This certainly fixed the html example, but not the real problem. The reason was that one of the parent elements already had an absolute position of the position, but did not have codes. Setting these elements to the left and top position did the trick.

0


a source to share


3 answers


Set the ccs tables to position: relative and your image to position: absolute and give it top: 0px and left: 0px;



+1


a source


use CSS positioning:



#imgLogo {
position:absolute;
top:100px;
left:100px;
}

      

+1


a source


Absolute positioning is the key:

#imgLogo {
    position: absolute;
    top: 0;    // This is the default value, but whatever
    left: 0;   // ^
}

      

0


a source







All Articles