使用 CSS3 在透明方框中顯示文字
opacity 屬性用於建立透明文字框。使用 background 屬性在透明框中設定影像。由於我們設定了不透明度,它將使文字框中出現的文字和影像透明。
建立一個 div 容器
設定了 div 容器 −
<div class="transparentBox">
<div class="transparentText">
<p>This is some random text inside the transparent box</p>
</div>
</div>
透明文字框
在上述父級 div 中,設定了文字框子級 div −
<div class="transparentText"> <p>This is some random text inside the transparent box</p> </div>
設定一張圖片
對於透明框,使用 background 屬性設定影像。影像源設定在 url() 中 −
transparentBox {
background: url("https://tutorialspoint.tw/images/dbms_icon.svg") repeat;
border: 2px solid black;
}
透明文字
在框中,設定不透明度屬性以實現透明 −
.transparentText {
margin: 30px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
}
示例
要使用 CSS3 設定透明框中的文字,程式碼如下 −
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.transparentBox {
background: url("https://tutorialspoint.tw/images/dbms_icon.svg") repeat;
border: 2px solid black;
}
.transparentText {
margin: 30px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
}
.transparentText p {
margin: 5%;
font-weight: bolder;
color: #000000;
font-size: 20px;
}
</style>
</head>
<body>
<h1>Text in transparent box example</h1>
<div class="transparentBox">
<div class="transparentText">
<p>This is some random text inside the transparent box</p>
</div>
</div>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP