Computer >> Computer tutorials >  >> Programming >> CSS

How to position text to top right position on an image with CSS


To position text to top right, use the right and top property. You can try to run the following code to implement it:

Example

<!DOCTYPE html>
<html>
   <head>
      <style>
         .box {
            position: relative;
         }
         img {
            width: 100%;
            height: auto;
            opacity: 0.6;
         }
         .direction {
            position: absolute;
            top: 10px;
            right: 19px;
            font-size: 13px;
         }
      </style>
   </head>
   <body>
      <h1>Heading One</h1>
      <p>Below image has text in the top right:</p>
      <div class = "box">
         <img src = "https://www.tutorialspoint.com/python/images/python_data_science.jpg" alt = "Tutorial"
            width = "800" height = "400">
         <div class="direction">Top Right Corner</div>
      </div>
   </body>
</html>