Clickable icon with link

2019-03-06 02:59发布

问题:

I have an icon list made of social media but they're only clickable on the letter of the icon, I want it to be clickable on any spot but I have to click on the "F" of facebook:

On the facebook icon, I have to click literally on the "F", it doesn't work if I click on the blue spot, how can I fix this? Here's my code:

<div class="leftside">
    <ul class="socialmediaicons">
      <li><a href="https://www.facebook.com/EnUnChasquido/"><i class="fa fa-facebook"></i></li></a>
      <li><i class="fa fa-instagram"></i></li>
      <li><i class="fa fa-twitter"></i></li>
      <li><i class="fa fa-youtube"></i></li>
    </ul>
  </div>

回答1:

A possible workaround will be using css. anchor is inline element and it only wraps the icon. We need anchor to cover whole area in li

using css

ul li a{
    display:inline-block;
    width:100%;
    height:100%;
}


回答2:

li{
	border:1px solid red;
	display: inline-block;
}
.fa{
	padding:15px;
	padding-bottom: 15px;
	padding-top:15px;

}
a{
	display: block;
}
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
	<div class="leftside">
    <ul class="socialmediaicons">
      <li><a href="https://www.facebook.com/EnUnChasquido/"><i class="fa fa-facebook"></i></a></li>
      <li><i class="fa fa-instagram"></i></li>
      <li><i class="fa fa-twitter"></i></li>
      <li><i class="fa fa-youtube"></i></li>
    </ul>
  </div>
</body>
</html>

   <html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
li{
    border:1px solid red;
    display: inline-block;
}
.fa{
    padding:15px;
    padding-bottom: 15px;
    padding-top:15px;

}
a{
    display: block;
}
</style>
</head>
<body>
    <div class="leftside">
    <ul class="socialmediaicons">
      <li><a href="https://www.facebook.com/EnUnChasquido/"><i class="fa fa-facebook"></i></li></a>
      <li><i class="fa fa-instagram"></i></li>
      <li><i class="fa fa-twitter"></i></li>
      <li><i class="fa fa-youtube"></i></li>
    </ul>
  </div>
</body>
</html>


回答3:

I would use inherit for de with and height of the li items. I used flexbox to align everything in the center. When hyperlinks are created for the other icons, you can remove the flexbox settings for li.

li {
  width: 50px;
  height: 50px;
  background-color: pink;
  border: thin solid black;
  list-style: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

li>a {
  width: inherit;
  height: inherit;
  display: flex;
  justify-content: center;
  align-items: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="leftside">
  <ul class="socialmediaicons">
    <li><a href="https://www.facebook.com/EnUnChasquido/"><i class="fa fa-facebook"></i></a></li>
    <li><i class="fa fa-instagram"></i></li>
    <li><i class="fa fa-twitter"></i></li>
    <li><i class="fa fa-youtube"></i></li>
  </ul>
</div>