出于某种原因,我只能在我的内容上做<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');
}
<!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>
'href' 属性不适用于 'div' 元素。"href"属性仅适用于"a"标签。因此,将"div"元素包装在"a"元素中。
<a href = "index.html">
<div class ="group-content">
<!-- Insert your code here -->
</div>
</a>
或者你可以将"a"元素包装在"div"元素中
<div class ="group-content">
<a href = "index.html">
<!-- Insert your code here -->
</a>
</div>
<div>
不能具有href
属性。 href
只能在<a>
、<link>
或<base>
上起作用。使所有这些<div>
链接到index.html
的有效方法是用<a>
nchor包装.group-content
,然后设置<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>
你的代码
<div class="content" href="index.html">
不会按您希望的方式工作。相反,你需要用Javascript对行为进行编程:
<div class="content" onclick="window.location.href='index.html';">
试试这个
<a href="https://steamcommunity.com/id/kumo99" target="_blank">Made by Kumo © 2018</a>