使用 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.com/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.com/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