HTML Split SINGLE BACKGROUND IMAGE into two equal links (top and bottom)
HTML Split SINGLE BACKGROUND IMAGE into two equal links (top and bottom)
I am just learning HTML. Is there a way without using image mapping to split a background image into 50-50%, with each half linking to an external link? I put style=0% and 50% to split the links into the top 50% and bottom 50%, but it doesn't split the image in two.
This is what I have:
<!DOCTYPE html>
<html>
<head>
<title>Page 2</title>
<link href="https://fonts.googleapis.com/css?family=Proxima+Nova" rel="stylesheet">
</head>
<body>
<div class="image">
<center><img src="{% static 'picture.png' %}" alt="image" /></center>
<a href="link1" style="top: 0%;"></a>
<a href="link2" style="top: 50%;"></a>
</div>
</body>
</html>
Thanks in advance!
<center> is a deprecated tag. Use CSS to center an element.
– ecg8
Jul 1 at 3:26
3 Answers
3
I have created something that does what you are looking for. It has the following limitations:
* {
margin: 0px;
padding: 0px;
}
.top {
height: 200px;
overflow: hidden;
position: absolute;
z-index: 2;
}
.bottom {
position: absolute;
}
<a class="top" href="https://www.google.com"><img src="https://placeholdit.co//i/400x400" /></a>
<a class="bottom" href="https://www.cnn.com"><img src="https://placeholdit.co//i/400x400" /></a>
Just put the img
as a background-image
via css, then position the links on top of a container with that background-image:
img
background-image
.split-link-image {
height: 400px;
background: transparent url(http://placekitten.com/400/400) no-repeat 0 0;
background-size: cover;
width: 400px;
position: relative;
}
.split-link-image a {
position: absolute;
left: 0;
right: 0;
height: 50%;
display: block;
}
.split-link-image a:first-child {
top: 0;
}
.split-link-image a:last-child {
bottom: 0;
}
<div class="split-link-image">
<a href="#top"></a>
<a href="#bottom"></a>
</div>
This is a simple sample:
<div style="position: relative; width:500px; height:500px; background-color: #667799">
<a style="display: inline-block; position: absolute; top:0; left:0; height:50%; width:100%; box-sizing: border-box; border:solid 1px red" href="addr1"></a>
<a style="display: inline-block; position: absolute; top:50%; left:0; height:50%; width:100%; box-sizing: border-box; border:solid 1px orange" href="addr2"></a>
</div>
My wrapper is div
and i use background-color for wrapper of links ;you must use background-image:url(imageAdress);
Also you don't need border
of a
tags.
div
background-image:url(imageAdress);
border
a
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Use an image map
– miknik
Jul 1 at 1:23