将Div中的背景图像转换为链接

时间:2017-08-18 20:38:05

标签: html css background-image href

虽然有很多问题涉及将背景图像转换为链接,或者在div中创建链接,但我很难找到将div中的背景图像链接起来的解决方案。具体来说:https://jsfiddle.net/pmcgswf4/5/。理想情况下,当用户选择图像或标题时,应将它们带到“personal_project_pages / crazyhearts.html”。

谢谢!

HTML:

    <li>
        <div id="crazyhearts">
            <div class="projects">
                <h2><a href=personal_project_pages/crazyhearts.html class = "alpha"> Crazy Hearts Cutting Board </a></h2>
            </div>
        </div>
    </li>

CSS:

/* Projects */
.projects {border-style: solid;
    width: 99.5%;
    height: 100%;
    /**  min-width: 630px;   **/
    min-height: 200px;
}

#crazyhearts {
    background:url("https://c1.staticflickr.com/5/4321/36112755175_f7f9ba8b84_b.jpg") no-repeat 0% 30%;
    background-size: cover;
    width: 100%;
    position: relative;
}

a {
  color: #214E34;
  font-family: 'Raleway', sans-serif;
  font-size: 13px;
  font-weight: 900;
  text-align: left;
  text-transform: uppercase;
  text-decoration: none;
  letter-spacing: 2px;
}

h2 {
  color: whitesmoke;
  font-family: 'Orbitron', sans-serif;
  font-size: 28px;
  font-weight: 500;
  text-align: left;
  text-transform: uppercase;
  background-color: rgba(0, 0, 0, 0.9);
}

2 个答案:

答案 0 :(得分:2)

<li>
  <div id="crazyhearts">
    <a href="personal_project_pages/crazyhearts.html" class = "alpha">
        <div class="projects">
            <h2> Crazy Hearts Cutting Board </h2>
        </div>
    </a>
  </div>
</li>

你在href属性周围缺少" ",HTML5允许你包装标签

答案 1 :(得分:0)

HTML5允许您将div包装在锚标记中。

    <li>
      <div id="crazyhearts">
        <a href=personal_project_pages/crazyhearts.html class = "alpha">
            <div class="projects">
                <h2> Crazy Hearts Cutting Board </h2>
            </div>
        </a>
      </div>
    </li>
相关问题