CSS Layout How to - Fix to top left corner








Question

We would like to know how to fix to top left corner.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#canvasContainer {<!--from  w w w  . ja  v  a  2  s .  c om-->
    position: relative;
}
#canvasContainer canvas {
    width: 400px;
    height: 300px;
    background: blue;
}
#canvasContainer div.overlay {
    position: absolute;
    padding: 10px;
    background: #eee;
    top: 0px;
    left: 0px;
}
</style>
</head>
<body>
<div id="canvasContainer">
    <canvas></canvas>
    <div class="overlay top left">
        Top left stuff
    </div>
</div>
</body>
</html>

The code above is rendered as follows: