On my website I have two images/buttons called Get Started and Learn More. The images are wrapped with an anchor tag to take you to separate pages. However, the clickable area is much larger then the actual image. And I'm not sure why. Any help would be appreciated.
HTML
<!--button Holder-->
<div class="d-all m-all" id="buttonHolder">
<div class="d4-d6 m-all" id="getStarted">
<a href="contact.html#contactFormContainer"><img id="getStartedButton" src="images/get_started_button_vi.jpg" height="52"></a>
</div>
<div class="d7-d9 m-all" id="learnMore">
<a href="services.html"><img id="learnMoreButton" src="images/learn_more__button_vi.jpg" height="52" ></a>
</div>
<div class="m-all d-all">
<hr class="hrBreakTop"/>
</div>
</div><!--End button holder-->
CSS
/*Buttons*/
#buttonHolder{
}
#buttonHolder img{
margin-top:155px;
margin-bottom:10px;
display:block;
margin-left: auto;
margin-right: auto;
}
/*Reduce button sizes on mobile*/
@media all and (min-width:451px) and (max-width: 989px){
#buttonHolder img{
margin-top:65px;
width:45%;
display:block;
margin-left: auto;
margin-right: auto;
height:auto;
}
}
/*Reduce padding top on mobile*/
@media all and (min-width:0px) and (max-width: 450px){
#buttonHolder img{
margin-top:0px;
}
}
#getStarted{
}
#getStartedButton{
margin-right:20px;
}
/*Add top margin to button to prevent merging with VoipInnovations middle logo*/
@media all and (min-width: 0px) and (max-width: 989px){
#getStartedButton{
margin-top:15px;
}
}
#learnMore{
}
#learnMoreButton{
margin-left:20px;
}
You need to make your anchor display: block or display: inline-block; and then it will accept the width and height values.
An anchor is an inline element by default so you can't add dimensions to it unless you change its display property.
HTML <a> Tag. The <a> tag (anchor tag) in HTML is used to create a hyperlink on the webpage. This hyperlink is used to link the webpage to other web pages or some section of the same web page. It's either used to provide an absolute reference or a relative reference as its “href” value.
For me it helped to make the image display:block
. The reason why it cannot be inline is (i heard) the white-space reserved for characters that go bellow the line like "y".
Its caused by the margins you have on the images in the links. You want to move the margins to the anchor tags
#buttonHolder a {
display: block;
margin: 155px auto 10px;
width: 226px;
}
And give the images no margin
#buttonHolder img {
display: block;
margin: 0;
}
just set float:left property on image like this and your problem will be solved
#buttonHolder img {
float:left;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With