如何向背景图像添加超链接?

pmc*_*lee 3 html css

我想添加一个指向该背景图像的超链接。我应该在样式表中创建一个新类吗?(当我尝试调用新类时,图像消失了)。

body{
  background-image:url('http://thehypebr.com/wp-content/uploads/2010/09/boundless-sem-branco-2.jpg');
  background-repeat:no-repeat;
  background-attachment:fixed;
  line-height:20px; font-size:14px;
  font-family:"Trebuchet MS";
  margin:0
}
Run Code Online (Sandbox Code Playgroud)

编辑:现在顶部和底部有空白(由新的 div 类创建?)

Rus*_*ias 5

您正在标签background-image上使用 a body。为其分配超链接是不可能的。

另外,是什么阻止您在标签中使用它img?这似乎是语义上有效的事情:

<a href="#"><img src="http://thehypebr.com/wp-content/uploads/2010/09/boundless-sem-branco-2.jpg" alt="Image" /></a>
Run Code Online (Sandbox Code Playgroud)

但是,如果您必须将其用作背景图像,则最好创建一个附加类。