出于某种原因,我只能对我的内容<a href=""> </a>
进行链接,当我尝试将其添加到整个div时,它根本不起作用。有谁知道发生了什么,我试图让<div class="content">
作为一个链接。到目前为止<div class="content" href="index.html">
没有用。我在这里编码有问题,还是我错过了一个错误?感谢。
body {
background-color: #323232;
width: 100%;
padding: 0;
margin: 0;
font-family: Lato;
}
nav a {
color: #fff;
text-decoration: none;
padding: 20px 25px;
display: inline-block;
}
.fixed-header, .fixed-footer {
background: #333;
color: #fff;
width: 100%;
position: fixed;
text-align: center;
z-index: 10;
background-color: #202020;
}
.fixed-header {
top: 0;
}
.fixed-footer {
bottom: 0;
padding: 20px 0px;
}
.fixed-header a:hover {
color: #c1c1c1;
}
.fixed-footer a {
color: #fff;
font-weight: lighter;
text-decoration: none;
}
.group-content {
max-width: 960px;
text-align: center;
width: 75%;
margin: 100px auto;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
.group-content h3 {
margin-top: 10px;
font-weight: normal;
font-size: 20px;
color: white;
}
.group-content p {
margin-top: 3px;
font-weight: lighter;
font-size: 20px;
color: white;
}
.content {
width: 30%;
background-color: #202020;
display: flex;
flex-direction: column;
padding: 20px 0 20px 0;
align-items: center;
margin-top: 20px;
}
.content >* {
max-width: 200px;
text-align: center;
margin: 0;
}
@font-face {
font-family: "Lato";
font-weight: normal;
font-style: normal;
src: url('fonts/Lato-Regular.eot'),
src: url('fonts/Lato-Regular.eot?#iefix') format('embedded-opentype'),
url('fonts/Lato-Regular.ttf') format('truetype'),
url('fonts/Lato-Regular.woff') format('woff'),
url('fonts/Lato-Regular.woff2') format('woff2');
}
@font-face {
font-family: "Lato";
font-weight: bold;
font-style: normal;
src: url('fonts/Lato-Bold.eot'),
src: url('fonts/Lato-Bold.eot?#iefix') format('embedded-opentype'),
url('fonts/Lato-Bold.ttf') format('truetype'),
url('fonts/Lato-Bold.woff') format('woff'),
url('fonts/Lato-Bold.woff2') format('woff2');
}
@font-face {
font-family: "Lato";
font-weight: lighter;
font-style: normal;
src: url('fonts/Lato-Light.eot'),
src: url('fonts/Lato-Light.eot?#iefix') format('embedded-opentype'),
url('fonts/Lato-Light.ttf') format('truetype'),
url('fonts/Lato-Light.woff') format('woff'),
url('fonts/Lato-Light.woff2') format('woff2');
}
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kumo99.cf</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="icon" href="favicon.ico">
</head>
<body>
<div class="fixed-header">
<nav>
<a href="index.html">HOME</a>
<a href="projects.html">PROJECTS</a>
<a href="about.html">ABOUT</a>
</nav>
</div>
<div class="fixed-footer">
<a href="https://steamcommunity.com/id/kumo99">Made by Kumo © 2018</a>
</div>
<div class="group-content", href="index.html">
<div class="content">
<img src="images/arma.png">
<h3>Arma 3: Exile Server</h3>
<p>A project for improving the exile mod.</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
</div>
</body>
</html>
&#13;
答案 0 :(得分:3)
'href'属性不适用于'div'元素。 'href'属性仅适用于'a'标记。所以将'div'元素包装在'a'元素中。
<a href = "index.html">
<div class ="group-content">
<!-- Insert your code here -->
</div>
</a>
或者你可以在'div'元素中包含'a'元素
<div class ="group-content">
<a href = "index.html">
<!-- Insert your code here -->
</a>
</div>
答案 1 :(得分:2)
<div>
不能拥有href
属性。 href
只能在<a>
nchor,<link>
或<base>
上运行。将所有<div>
链接到index.html
的有效方法是用.group-content
nchor包裹<a>
,然后设置<a>
nchor的样式,使其行为正常比如<div>
。
<a href='index.html' style='display:block; text-decoration:none'>
<div class='group-content'>...</div>
</a>
body {
background-color: #323232;
width: 100%;
padding: 0;
margin: 0;
font-family: Lato;
}
nav a {
color: #fff;
text-decoration: none;
padding: 20px 25px;
display: inline-block;
}
.fixed-header, .fixed-footer {
background: #333;
color: #fff;
width: 100%;
position: fixed;
text-align: center;
z-index: 10;
background-color: #202020;
}
.fixed-header {
top: 0;
}
.fixed-footer {
bottom: 0;
padding: 20px 0px;
}
.fixed-header a:hover {
color: #c1c1c1;
}
.fixed-footer a {
color: #fff;
font-weight: lighter;
text-decoration: none;
}
.group-content {
max-width: 960px;
text-align: center;
width: 75%;
margin: 100px auto;
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
.group-content h3 {
margin-top: 10px;
font-weight: normal;
font-size: 20px;
color: white;
}
.group-content p {
margin-top: 3px;
font-weight: lighter;
font-size: 20px;
color: white;
}
.content {
width: 30%;
background-color: #202020;
display: flex;
flex-direction: column;
padding: 20px 0 20px 0;
align-items: center;
margin-top: 20px;
}
.content >* {
max-width: 200px;
text-align: center;
margin: 0;
}
@font-face {
font-family: "Lato";
font-weight: normal;
font-style: normal;
src: url('fonts/Lato-Regular.eot'),
src: url('fonts/Lato-Regular.eot?#iefix') format('embedded-opentype'),
url('fonts/Lato-Regular.ttf') format('truetype'),
url('fonts/Lato-Regular.woff') format('woff'),
url('fonts/Lato-Regular.woff2') format('woff2');
}
@font-face {
font-family: "Lato";
font-weight: bold;
font-style: normal;
src: url('fonts/Lato-Bold.eot'),
src: url('fonts/Lato-Bold.eot?#iefix') format('embedded-opentype'),
url('fonts/Lato-Bold.ttf') format('truetype'),
url('fonts/Lato-Bold.woff') format('woff'),
url('fonts/Lato-Bold.woff2') format('woff2');
}
@font-face {
font-family: "Lato";
font-weight: lighter;
font-style: normal;
src: url('fonts/Lato-Light.eot'),
src: url('fonts/Lato-Light.eot?#iefix') format('embedded-opentype'),
url('fonts/Lato-Light.ttf') format('truetype'),
url('fonts/Lato-Light.woff') format('woff'),
url('fonts/Lato-Light.woff2') format('woff2');
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Kumo99.cf</title>
<meta charset="UTF-8">
<link rel="icon" href="favicon.ico">
</head>
<body>
<div class="fixed-header">
<nav>
<a href="index.html">HOME</a>
<a href="projects.html">PROJECTS</a>
<a href="about.html">ABOUT</a>
</nav>
</div>
<div class="fixed-footer">
<a href="https://steamcommunity.com/id/kumo99">Made by Kumo © 2018</a>
</div>
<a href="index.html" style='display:block;text-decoration:none'>
<div class="group-content">
<div class="content">
<img src="images/arma.png">
<h3>Arma 3: Exile Server</h3>
<p>A project for improving the exile mod.</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
<div class="content">
<img src="images/soon.png">
<h3>Reserved Space</h3>
<p>Reserved space for future projects</p>
</div>
</div>
</a>
</body>
</html>
答案 2 :(得分:0)
您的
代码<div class="content" href="index.html">
无法按您的意愿运作。相反,您需要使用Javascript编写行为:
<div class="content" onclick="window.location.href='index.html';">
答案 3 :(得分:0)
试试这个
<a href="https://steamcommunity.com/id/kumo99" target="_blank">Made by Kumo © 2018</a>
&#13;