如何使用 CSS 將文字定位到影像的左上角
要將文字定位到左上角,請使用 left 和 top 屬性。你可以嘗試執行以下程式碼,將文字定位到影像的左上角位置 -
示例
<!DOCTYPE html>
<html>
<head>
<style>
.box {
position: relative;
}
img {
width: 100%;
height: auto;
opacity: 0.6;
}
.direction {
position: absolute;
top: 10px;
left: 19px;
font-size: 13px;
}
</style>
</head>
<body>
<h1>Heading One</h1>
<p>Below image has text in the top left:</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 Left Corner</div>
</div>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP