为什么href不能处理我的内容?

问题描述 投票:1回答:4

出于某种原因,我只能在我的内容上做<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>
html css hyperlink
4个回答
2
投票

<div>不能具有href属性。 href只能在<a>nchor,<link><base>上发挥作用。使所有这些<div>s与index.html相关联的有效方法是用.group-contentnchor包裹<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>

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>

0
投票

你的代码

<div class="content" href="index.html">

不会像你想要的那样工作。相反,您需要使用Javascript编写行为:

<div class="content" onclick="window.location.href='index.html';">

0
投票

试试这个

<a href="https://steamcommunity.com/id/kumo99" target="_blank">Made by Kumo © 2018</a>
© www.soinside.com 2019 - 2024. All rights reserved.