如何使div成为一个链接

时间:2017-02-22 00:03:08

标签: html css hyperlink

我有一个带有背景图像的div,它由原始div内部的两个div分隔。如何制作在新标签中打开的两个div可点击链接?

我四处搜索,我理解的唯一建议是使用JavaScript,但是它不适用于所有浏览器吗?

HTML:

<div class="SocialMedia">

    <div class="icon1" onclick="location.href='https://www.facebook.com/DRC.Race.Leathers';" target="_blank" style="cursor:pointer;"></div>
    <div class="icon2" onclick="location.href='https://twitter.com/DRC_Leathers';" target="_blank" style="cursor:pointer;"></div>

    <span>Make sure to visit our social media pages to keep up to date with the latest from DRC</span>

</div> <!-- End of SocialMedia -->

CSS:

    .SocialMedia {
background-color: #000;
float: left;
margin: 10px;
width: 440px;
height: 330px;
background-image: url('Images/Social-Media.png');
border: 5px solid #000;
text-align: center;
font-size: 10;
color: #fff;
position: relative;
}

.SocialMedia span {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}

.icon1 {
width: 180px;
height: 180px;
float: left;
}

.icon2 {
width: 180px;
height: 180px;
float: right;
}

1 个答案:

答案 0 :(得分:1)

没关系,我意识到我的错误

HTML:

<div class="SocialMedia">

    <a href="https://twitter.com/DRC_Leathers" target="_blank"><div class="icon1"></div></a>
    <a href="https://twitter.com/DRC_Leathers" target="_blank"><div class="icon2"></div></a>

    <span>Make sure to visit our social media pages to keep up to date with the latest from DRC</span>

</div> <!-- End of SocialMedia -->

CSS保持不变