ウェブサイトの他の場所を見て、htmlの背景画像をリンクにするのは少し難しいように思えました。周りを見回して、Javaスクリプトを使用することでうまくいくはずだという誰かの提案に出くわしました。しかし、アイデアをテストする際に、私は運がありませんでした。
誰かが私がどこで間違っているのか指摘してくれたらとてもありがたいです。
私は次のhtmlとjavascriptコードを持っています:
<html>
<head>
<link href = "style1.css" rel = "stylesheet" type = "text/css">
</head>
<div id = "header">
Header
</div>
<body>
<div id = "body">
<div class = "container">
</div>
</div>
</body>
</html>
<script>
document.getElementById('container').onclick = function() {
window.location = 'http://www.google.com/';
}
</script>
私は次のCSSも持っています:
#header{
width:100%;
height:50px;
background-color:black;
}
#body {
width:100%;
height:2000px;
background-image:url('uploads/1.jpg');
cursor:pointer;
}
.container{
width: 1000px;
margin-right: auto;
margin-left: auto;
height: 1000px;
background-color:white;
}