2017-02-22 76 views
0

我有一個背景圖像的div,由原始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; 
} 
+0

用'A'代替'DIV'? –

+0

你需要使用'window.open'而不是'location.href'來打開一個新窗口,但是通過一個方形孔敲擊圓形釘子並使一個div像超鏈接一樣行爲是一個壞主意。它會殺死殘障用戶的可用性,阻止網絡爬蟲/索引等等。總而言之,這是一個壞主意。 –

回答

0

沒關係,我意識到自己的錯誤

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保持不變