Reputation: 158
I am new to HTML and CSS. I have a row of social media icons that link to their respective pages. The HTML for that:
<div id="social">
<a target="_blank" href="https://www.facebook.com/">
<img title="Facebook" alt="Facebook" src="img/social/facebook.png" />
</a>
<a target="_blank" href="https://twitter.com/">
<img title="Twitter" alt="Twitter" src="img/social/twitter.png" />
</a>
<a target="_blank" href="https://instagram.com/">
<img title="Instagram" alt="Instagram" src="img/social/instagram.png" />
</a>
</div>
Here is the relevant CSS:
#social {
text-align: center;
}
#social img {
width: 6%;
height: 6%;
padding-right: 20px;
}
The problem is that the 20px of right padding is apart of the link, which is sloppy. How do I create space between the icons without that space being linked? Cheers.
Upvotes: 0
Views: 71
Reputation: 11
Instead of targeting #social img
in the css, try using #social a
and margin-right: 20px
instead of padding-right
.
Upvotes: 1
Reputation: 4503
use margin
#social {
text-align: center;
}
#social img {
width: 6%;
height: 6%;
/*padding-right: 20px;*/
margin-right: 20px;
}
<div id="social">
<a target="_blank" href="https://www.facebook.com/">
<img title="Facebook" alt="Facebook" src="img/social/facebook.png" />
</a>
<a target="_blank" href="https://twitter.com/">
<img title="Twitter" alt="Twitter" src="img/social/twitter.png" />
</a>
<a target="_blank" href="https://instagram.com/">
<img title="Instagram" alt="Instagram" src="img/social/instagram.png" />
</a>
</div>
Upvotes: 1
Reputation: 32275
Provide margin between the anchors
#social a {
width: 6%;
height: 6%;
margin-right: 20px;
}
Upvotes: 1
Reputation: 71160
Simply set a margin on the a
elements (except the last one, where a margin would be both redundant, and potentially layout impacting):
#social {
text-align: center;
}
#social img {
width: 6%;
height: 6%;
}
#social a:not(:last-of-type){
margin-right:20px;
}
Upvotes: 2