如何使用 CSS 将文本定位到图片左下角

cssweb developmentfront end technology更新于 2024/8/20 7:08:17

要将文本定位到左下角,请使用 bottom 和 left 属性。您可以尝试运行以下代码,将文本定位到图片左下角

示例

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

相关文章


有用资源