【发布时间】:2015-01-09 15:14:03
【问题描述】:
我实际上是一个全新的编码员,刚开始使用 HTML(昨天开始),我在一些我似乎不太知道该怎么做的事情上遇到了一些麻烦。我使用 CSS 使主页上的图像透明,但不幸的是,它使所有其他图像也透明,尽管所有其他图像都是不透明的。这是我的 index.html 的源代码
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-image: url("bg.png");
background-color: #cccccc;
}
h1 {color:green}
p {color:blue}
h1 {
text-align: center;
}
p {
text-align: center;
}
header {
position:fixed;
top:0;
background-color:#333;
opacity: 0.4;
width:100%;
height:40px;
padding:20px;
text-align:center;
}
footer {
width: 100%;
bottom: 0;
background-color:#333;
opacity: 0.4;
position: fixed;
text-align:center;
}
#main{
padding-top:100px;
text-align:center;
}
img {
opacity: 0.4;
}
img:hover {
opacity: 1.4;
}
</style>
</head>
<title>Jordan's Test Site (iCarlos)</title>
<body center>
<header> Deal with it B)</header>
<div id="main">
<p><img src="giphy.gif" alt=Deal with it! style="width:500px;height:273px"></p>
<p>Hello! I am a website. Testing, testing, 1 2 3.</p>
<p><a href="yep.html"><img src="deal-with-it.png" alt=Clic! style="width:450px;height:80px"></a></p>
<p><a href="table.html">Click here to go to the table!</a></p>
</div>
<footer>
<p><a href="index.html"><img src="home.png" alt=source style=width:124;height:124></a></p>
</footer>
</body /center>
谢谢你们的帮助,伙计们!
【问题讨论】:
-
opacity: 1.4不是有效值。不透明度值范围从 0(透明)到 1(纯色)。 -
在添加不透明度时更具体
img.classname -
为图像添加一个类然后给出,以便它只适用于
img.classname { opacity: 0.4; }