使用 CSS 將文字定位到圖片的右上角


要將文字定位到右上角,請使用 right 和 top 屬性。你可以嘗試執行以下程式碼來實現它

示例

現場演示

<!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://tutorialspoint.tw/python/images/python_data_science.jpg" alt = "Tutorial"
            width = "800" height = "400">
         <div class="direction">Top Right Corner</div>
      </div>
   </body>
</html>

更新於: 24-6-2020

1 千次瀏覽

開啟你的 事業

完成課程獲得認證

開始學習
廣告
© . All rights reserved.